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
#include <cstdio>

long A[200000];

int main()
{
  int t, n;
  scanf("%i ", &t);
  while (t--)
  {
    scanf("%i ", &n);
    int m = 0;
    long a, s = 0, t = 0;
    for (int i = 0; i<n; i++)
    {
      scanf("%li ", &a);
      if (a>0) A[m++] = a, t += a;
    }
    while (s*(s-1)*(s-2)/6<t) s++;
    while (1)
    {
      long p = 0, q = s-p-1;
      for (int i = 0; i<m; i++)
      {
        long r = 0;
        while (a>r && q>1) p++, q--, r += p*q;
        if (a>r) goto next;
      }
      break;
      next:
      s++;
    }
    printf("%li\n", s);
  }
  return 0;
}