题目
题意:
题目很长,其实就是对于每一个 a i a_i ai,如果此时院子里有 x x x个人,并且 x ≤ a i x\leq a_i x≤ai,那么此时的 a i a_i ai就可以进入院子中,然后 x + 1 x+1 x+1,问最后最多能有多少个人进院子。
思路:
我们肯定要使 a i a_i ai尽量小的先进去,这样人数就可以越来越大所以先排序,因为人数可以一起进,那么我们就直接把 x x x用 i i i代替,因为如果后面的可以进,那么前面的肯定也可以进, 所以就是要找最大的满足 a i ≤ i a_i\leq i ai≤i的 i i i,最后要 + 1 +1 +1,因为还有一个主人使本来就在院子里的。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
inline void out(int x) {
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
inline void debug(ll x) {cout << x << endl;}
inline void debugs(string s) {cout << s << endl;}
const int maxn = 1e5 + 10;
int a[maxn];
int main() {
int t;
read(t);
while (t--) {
int n;
read(n);
for (int i = 1; i <= n; i++) read(a[i]);
sort(a + 1, a + n + 1);
int ans = 0;
for (int i = 1; i <= n; i++) {
if (a[i] <= i) ans = i;
}
out(ans + 1);
putchar('\n');
}
return 0;
}