**“[Riddle] Balanced Stone Heaps solution codeforces”**

There are 𝑛n heaps of stone. The 𝑖i-th heap has ℎ𝑖hi stones. You want to change the number of stones in the heap by performing the following process once:

- You go through the heaps from the 33-rd heap to the 𝑛n-th heap, in this order.
- Let 𝑖i be the number of the current heap.
- You can choose a number 𝑑d (0≤3⋅𝑑≤ℎ𝑖0≤3⋅d≤hi), move 𝑑d stones from the 𝑖i-th heap to the (𝑖−1)(i−1)-th heap, and 2⋅𝑑2⋅d stones from the 𝑖i-th heap to the (𝑖−2)(i−2)-th heap.
- So after that ℎ𝑖hi is decreased by 3⋅𝑑3⋅d, ℎ𝑖−1hi−1 is increased by 𝑑d, and ℎ𝑖−2hi−2 is increased by 2⋅𝑑2⋅d.
- You can choose different or same 𝑑d for different operations. Some heaps may become empty, but they still count as heaps.

1 | https://wordpress.com | 92 | 88 |
---|---|---|---|

2 | https://www.weebly.com | 93 | 83 |

3 | https://www.wix.com | 94 | 86 |

4 | https://sites.google.com | 98 | 86 |

5 | https://www.tumblr.com |

What is the maximum number of stones in the smallest heap after the process?

**“[Riddle] Balanced Stone Heaps solution codeforces”**

Each test contains multiple test cases. The first line contains the number of test cases 𝑡t (1≤𝑡≤2⋅1051≤t≤2⋅105). Description of the test cases follows.

The first line of each test case contains a single integer 𝑛n (3≤𝑛≤2⋅1053≤n≤2⋅105).

The second lines of each test case contains 𝑛n integers ℎ1,ℎ2,ℎ3,…,ℎ𝑛h1,h2,h3,…,hn (1≤ℎ𝑖≤1091≤hi≤109).

It is guaranteed that the sum of 𝑛n over all test cases does not exceed 2⋅1052⋅105.

For each test case, print the maximum number of stones that the smallest heap can contain.

4 4 1 2 10 100 4 100 100 100 1 5 5 1 1 1 8 6 1 2 3 4 5 6

7 1 1 3

**“[Riddle] Balanced Stone Heaps solution codeforces”**

In the first test case, the initial heap sizes are [1,2,10,100][1,2,10,100]. We can move the stones as follows.

- move 33 stones and 66 from the 33-rd heap to the 22-nd and 11 heap respectively. The heap sizes will be [7,5,1,100][7,5,1,100];
- move 66 stones and 1212 stones from the last heap to the 33-rd and 22-nd heap respectively. The heap sizes will be [7,17,7,82][7,17,7,82].

In the second test case, the last heap is 11, and we can not increase its size.

In the third test case, it is better not to move any stones.

In the last test case, the final achievable configuration of the heaps can be [3,5,3,4,3,3][3,5,3,4,3,3].