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
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (auto i=(a); i<(b); i++)
#define FORD(i, a,  b) for (auto i=(a); i>(b); i--)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif

const int maxN = 1 << 18;
int n, T[maxN];

long long cnt(long long p, long long x, long long s)
{
	return p * x * s + x * (x-1) / 2 * (p + s) + x * (x-1) * (x-2) / 6;
}

bool check(int sum)
{
	int pref = 0;
	FOR(i, 0, n)
	{
		int x = 0;
		while (x <= sum and cnt(pref, x, sum-x) < T[i])
			++x;
		if (x > sum)
			return false;
		pref += x, sum -= x;
	}
	return true;
}

void solve()
{
	scanf ("%d", &n);
	FOR(i, 0, n)
		scanf ("%d", T+i);
	int a = 0, b = n * 200;
	while (b - a > 1)
	{
		int c = (a + b) / 2;
		(check(c) ? b : a) = c;
	}
	printf("%d\n", b);
}

int main()
{
	int tc = 1;
	scanf ("%d", &tc);	

	FOR(cid, 1, tc+1)
		solve();
	return 0;
}