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
83
84
85
86
87
88
#include <bits/stdc++.h>
using namespace std;
#define fwd(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) fwd(i, 0, n)
#define all(X) X.begin(), X.end()
#define sz(X) int(size(X))
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
using pii = pair<int, int>; using vi = vector<int>;
using ll = long long; using ld = long double;
#ifdef LOC
auto SS = signal(6, [](int) { *(int *)0 = 0; });
#define DTP(x, y) auto operator<<(auto &o, auto a) -> decltype(y, o) { o << "("; x; return o << ")"; }
auto operator<<(auto &o, auto a) -> decltype(all(a), o);
DTP(o << a.st << ", " << a.nd, a.nd);
DTP(for (auto i : a) o << i << ", ", all(a));
#define deb(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", [](auto... arg_) { (( cerr << arg_ << ", " ), ...) << '\n'; }(x)
#else
#define deb(...) 0
#endif

ll safemul(ll a, ll b) {
    return min(a * b, ll(1e9));
}
ll safemul(ll a, ll b, ll c) {
    return safemul(a, safemul(b, c));
}

ll ile(ll pr, ll tu, ll ne) {
    ll x = tu*(tu-1)*(tu-2) / 6;
    x += safemul(tu*(tu-1)/2, pr + ne);
    x += safemul(tu, pr, ne);
    return x;
}

bool check(const vector<ll> &a, ll sum) {
    ll pr = 0;

    rep(i, sz(a)) {
        ll l = -1, r = min(sum - pr + 1, 200LL);

        while (r - l > 1) {
            ll mid = (l + r) / 2;
            if (ile(pr, mid, sum-pr-mid) >= a[i])
                r = mid;
            else
                l = mid;
        }

        if (r == sum - pr + 1)
            return false;
        pr += r;
    }

    return true;
}

void solve() {
    int n;
    cin >> n;

    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll l = -1, r = 200 * n;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        if (check(a, mid))
            r = mid;
        else
            l = mid;
    }
    cout << r << '\n';
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(10);

    int z = 1;
    cin >> z;
    rep(_, z) solve();

    cout << flush;
    _Exit(0);
}