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
#include "bits/stdc++.h"

#define int long long
#define pi pair<long long, long long>
#define a3 array<long long, 3>

#define meow main

using namespace std;

int ugly(int i, int bf, int n) {
  return (i*(i-1)*(i-2))/6 + bf*(i*(i-1))/2 + bf * i * (n-bf-i) + (i*(i-1))/2*(n-bf-i);
}

void solve() {
  int n; cin >> n;
  vector<int> A(n);
  for(auto &a : A) cin >> a;

  auto try_solve = [&](int m) {
    int before = 0;
    for(int i=0; i<n; i++) {
      if(A[i] == 0) continue;
      if(i==n-1) {
        auto k = m - before;
        return ((k*(k-1)*(k-2))/6 + before*(k*(k-1))/2 >= A[i]);
      }
      bool did_break = false;
      for(int k=0; k<=m-before; k++) {
        if(ugly(k, before, m) >= A[i]) {
          before += k;
          did_break = true;
          break;
        }
      }

      if(!did_break) return false;
    }

    return true;
  };

  int jump = (1<<20);
  int curr = -1;
  while(jump) {
    if(!try_solve(jump + curr)) curr += jump;
    jump/=2;
  }

  cout << curr+1 << '\n';
}

signed meow() {
  cin.tie((ostream *)!ios::sync_with_stdio(false));
  int satori_moment;
  cin >> satori_moment;
  while (satori_moment--)
    solve();
  return 0;
}