/* -*- 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) { int c0 = cs[0], d = 1; for (int i = n + 1; i > 0 && d <= n; i--) { if (i >= x) c0 += cs[i]; else { int dc = d - cs[i]; if (dc <= 0) c0 += -dc; else d += dc; } } 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 + 1; while (x0 + 1 < x1) { int x = (x0 + x1) / 2; if (check(n, x)) x0 = x; else x1 = x; } printf("%d\n", x0); } return 0; }