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

#define st first
#define nd second
#define int long long

int n, q, t[200005];

int newton(int n, int k) {
    if(k > n) return 0;
    if(k == 1) return n;
    if(k == 2) return n * (n - 1) / 2;
    if(k == 3) return n * (n - 1) * (n - 2) / 6;
    return 0;
}

int check(int x) {
    int left = 0;
    for(int i = 0; i < n; i++) {
        int l = 0, r = x - left + 1;
        while(l < r) {
            int m = (l + r) / 2;
            int temp_res = 0;
            int comb1 = n > 2 ? (left * newton(m, 1) * (x - left - m)) : 0;
            int comb2 = n > 1 ? ((x - m) * newton(m, 2)) : 0;
            int comb3 = newton(m, 3);
            temp_res = comb1 + comb2 + comb3;
            if(temp_res >= t[i]) r = m;
            else l = m + 1;
        }
        if(l == x - left + 1) return false;
        left += l;
    }
    return true;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;
    while(q--) {
        cin >> n;
        for(int i = 0; i < n; i++) {
            cin >> t[i];
        }
        int l = 0, r = n + 10000;
        while(l < r) {
            int m = (l + r) / 2;
            if(check(m)) r = m;
            else l = m + 1;
        }
        cout << l << '\n';
    }
}