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
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int t,n,a[256*1024];
#define REP(i,n) for(int i=0;i<n;++i)
int total;
map<pair<int,int>,bool>memo;
bool f(int pos,int was){
//cerr<<'>'<<pos<<' '<<was<<endl;
  auto idx=make_pair(pos,was);
  if(memo.count(idx))return memo[idx];
  bool&res=memo[idx]=false;
  if(pos==n)return res=true;
//cerr<<"foo"<<endl;
  for(int x=0/*(pos==n-1?total-was:0)*/;x<=total-was&&x<=500;++x){
//cerr<<"X "<<x<<endl;
//cerr<<"total "<<total<<endl;
    int g=
      x*was*(total-was-x)
      +(x*(x-1)/2)*(total-x)
      +(x*(x-1)*(x-2)/6);
//cerr<<"G "<<g<<endl;
    if(g<a[pos])continue;
//cerr<<"bar"<<endl;
    if(f(pos+1,was+x))return res=true;
//cerr<<"baz"<<endl;
  }
//cerr<<"bax"<<endl;
  return res=false;
}
int main(){
  cin>>t;
  while(t--){
    cin>>n;
    REP(i,n)cin>>a[i];
    int l=2,p=36600000;
    while(l+1<p){
      total=(l+p)/2;
//      cerr<<l<<' '<<total<<' '<<p<<endl;
      memo.clear();
      if(f(0,0))p=total;else l=total;
    }
    cout<<p<<endl;
  }
  return 0;
}