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
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ll long long
#define dbg(x) cerr << #x << ": " << x << "\n"
#define mp make_pair

using namespace std;

const int N = 200005;
int tab[N];

int n;

bool check(int num)
{
    int pre = 0;
    for (int i = 1; i <= n; i++)
    {
        int a = -1;
        int b = min(200, num + 1);
        while (b - a > 1)
        {
            int c = (a + b) / 2;
            ll cnt = 0;
            int suf = num - c;
            if (i == n)
                suf = 0;
            cnt += 1ll * c * pre * suf;
            cnt += 1ll * c * (c - 1) / 2 * (pre + suf);
            cnt += 1ll * c * (c - 1) * (c - 2) / 6;
            if (cnt >= tab[i])
                b = c;
            else
                a = c;
        }
        // cout << b << " ";
        if (b == min(200, num + 1))
            return false;
        pre += b;
        num -= b;
        if (num < 0)
            return false;
    }
    return true;
}

void solve()
{
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        cin >> tab[i];
    }

    int a = -1;
    int b = int(200 * 1e6);
    while (b - a > 1)
    {
        int c = (a + b) / 2;
        if (check(c))
            b = c;
        else
            a = c;
    }
    cout << b << "\n";
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);

    int t;
    cin >> t;

    while (t--)
        solve();

    return 0;
}