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
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

long long count_pairs(int m) {
  if (m < 3)
    return 0;
  return (long long)(m - 1) * (m - 2) / 2;
}

bool is_valid(int m, const vector<int> &a) {
  for (int games : a) {
    long long possible_games = count_pairs(m);
    if (possible_games < games) {
      return false;
    }
  }
  return true;
}

int main() {
  int t;
  cin >> t;

  while (t--) {
    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }

    int left = 3, right = 200000;
    int result = right;

    while (left <= right) {
      int mid = (right + left) / 2;

      if (is_valid(mid, a)) {
        result = mid;
        right = mid - 1;
      } else {
        left = mid + 1;
      }
    }

    cout << result << "\n";
  }

  return 0;
}