/* -*- coding: utf-8 -*- * * 3780.cc: No.3780 Erase and Mex - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ using ll = long long; /* global variables */ int as[MAX_N], cs[MAX_N + 2]; /* subroutines */ bool check(int n, int x) { ll c0 = cs[0], d = 1; for (int i = n + 1; i > 0; i--) { if (i > x) c0 += cs[i]; else { if (cs[i] >= d) c0 += cs[i] - d; else d += d - cs[i]; } } return c0 >= d; } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); if (n == 1) { printf("%d\n", max(1, as[0])); continue; } fill(cs, cs + n + 2, 0); for (int i = 0; i < n; i++) cs[min(n + 1, as[i])]++; int x0 = 0, x1 = n; while (x0 + 1 < x1) { int x = (x0 + x1) / 2; if (check(n, x)) x0 = x; else x1 = x; } printf("%d\n", x1); } return 0; }