牛的学术圈
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
int c[N];
int n, l, h;
typedef pair<int, int> PII;
#define x first
#define y second
int main()
{
cin >> n >> l;
for(int i = 1; i <= n; i ++)cin >>c[i];
sort(c + 1, c + 1 + n,greater<int>());
PII mx = {0,0};
for(int j = 1, k = n; j <= n; j ++)
{
while(k && c[k] < j )k --;
if(c[j] >= j - 1 && j - k <= l)h = j;
}
cout << h <<endl;
}