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<bits/stdc++.h>
using namespace std;

#define ll long long

const int MAXN = 2e5 + 7;

ll tab[MAXN];

ll symbol(ll n, ll k){
    if(k == 2) return n * (n - 1) / 2;
    return n * (n - 1) * (n - 2) / 6;
}

ll calc_domek(ll x, ll bef, ll all){
    // cerr << "x: " << x << " bef: " << bef << " all: " << all << '\n';
    ll aft = all - x - bef;
    // cerr << "aft: " << aft << '\n';
    return symbol(x, 3) + symbol(x, 2) * (all - x) + (bef * x * aft);
}

bool spr(int x, int n){
    // cerr << "x: " << x << '\n';
    ll bef = 0;
    for(int i = 0; i < n; i++){
        if(!tab[i]) continue;
        if(calc_domek(x - bef, bef, x) < tab[i]) return 0;
        // cerr << "i: " << i << '\n';
        int p = 1, k = x - bef, s;
        while(p <= k){
            s = (p + k) / 2;
            // cerr << "s: " << s << '\n';
            ll xd = calc_domek(s, bef, x);
            // cerr << "calc_domek: " << xd << '\n';
            // cerr << "tab[i]: " << tab[i] << '\n';
            if(xd >= tab[i]) k = s - 1;
            else p = s + 1;
        }
        // cerr << "p k: " << p <<  ' ' << k << '\n';
        bef += p;
    }
    return 1;
}

int solve(int n){
    int p = 3, k = 1e6 + 7, s;
    while(p <= k){
        s = (p + k) / 2;
        if(spr(s, n)) k = s - 1;
        else p = s + 1;
    }
    // cerr << p << ' ' << k << '\n';
    return p;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t;
    cin >> t;
    // cerr << "t: " << t << '\n';
    while(t--){
        int n;
        cin >> n;
        // cerr << "n: " << n << '\n';
        for(int i = 0; i < n; i++) cin >> tab[i];
        cout << solve(n) << '\n';
        // cerr << spr(9, 2) << '\n';
    }
}