Răspuns:
Sa imi dai coroana asa cum ai promis. Sper sa mearga.
Explicație:
#include <bits/stdc++.h>
#define eps 1e-9
#define mod 1000000007
#define pi 3.14159265359
#define inf 1e18
#define NMAX 200000
using namespace std;
typedef long long ll;
typedef long double ld;
int n, y, x, F[NMAX + 5];
vector<int> A;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("hindex.in", "r", stdin);
freopen("hindex.out", "w", stdout);
cin>>n>>y;
for (int i=1; i<=n; i++)
{
cin>>x;
F[x]++;
}
for (int i=1; i<=NMAX; i++)
{
for (int j=1; j<=F[i]; j++)
{
A.push_back(i);
}
}
memset(F, 0, sizeof(F));
for (int i=A.size()-1, h=1; i>=0; i--, h++)
{
if (A[i] < h)
{
y -= (h-A[i]);
A[i] = h;
}
y -= F[h-1];
F[h] += F[h-1];
F[A[i]]++;
if (y < 0)
{
cout<<h-1;
return 0;
}
}
cout<<n;
return 0;
}