1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


using namespace std;

int64_t smallest_possible_center(int64_t left, int64_t right, int target){
    for (int64_t c=0; c<=right; c++){
        int64_t plays = left * c * (right-c) +
                (c*(c-1))/2 *(left+right-c) +
                (c*(c-1)*(c-2)) /6;
        if ( plays>=target ){
            return c;
        }
    }
    return -1;
}

bool possible ( vector<int> a, int64_t right){
    int64_t left=0;

    for (int i=0; i<a.size();i++){
        int64_t c = smallest_possible_center(left, right, a[i]);
        if (c==-1){
            return false;
        }
        left += c;
        right -=c;
    }
    return true;
}


uint64_t solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i=0; i<n;i++){
        cin>>a[i];
    }

    int64_t high =sqrt(*max_element(begin(a), end(a)))+10;
    high *= a.size();

    int64_t low =1;

    while (low<high){
        int64_t mid = low + (high-low)/2;
        if ( possible(a, mid) ){
            high = mid;
        }else{
            low = mid+1;
        }
    }
    return low;
}


int main()
{
    int t;
    cin>>t;
    for (int i=0;i<t; i++){
        cout<<" "<<solve()<<endl;
    }
    return 0;
}