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
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define deb(...)
#define DBP(...)
using namespace std;
using   ll         = long long;
using   vi         = vector<int>;
using   pii        = pair<int, int>;
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x)   for (auto& a : (x))
#define all(x)       (x).begin(), (x).end()
#define sz(x)        int((x).size())

void run();

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(12);
	run();
	cout << flush; _Exit(0);
}

__int128 get(__int128 b, __int128 m, __int128 a) {
	return b*m*a + m*(m-1)/2*(a+b) + m*(m-1)*(m-2)/6;
}

ll minCount(ll before, ll remain, ll wanted) {
	ll begin = 0, end = remain+2;
	while (begin+1 < end) {
		ll mid = (begin+end) / 2 - 1;
		__int128 got = get(before, mid, remain-mid);
		(got < wanted ? begin : end) = mid+1;
	}
	return begin <= remain ? begin : -1;
}

bool check(const vector<ll>& a, ll total) {
	ll before = 0;
	each(e, a) {
		ll x = minCount(before, total-before, e);
		if (x < 0) return 0;
		before += x;
	}
	return 1;
}

void solve() {
	int n; cin >> n;
	vector<ll> a(n);
	each(e, a) cin >> e;
	ll begin = 0, end = 1e9;
	while (begin+1 < end) {
		ll mid = (begin+end) / 2;
		(check(a, mid-1) ? end : begin) = mid;
	}
	cout << begin << '\n';
}

void run() {
	int t; cin >> t;
	while (t--) solve();
}