求助,改了好久没成功
#include<bits/stdc++.h>
using namespace std;
long long n,m,h,a[1000005],s,d;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(0),cin.tie(0);
ios::sync_with_stdio(0),cout.tie(0);
a[0]=-1;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
if(m==0){
cout<<a[n];
return 0;
}
h=a[n];
while(s<=m){
h--;
while(h<a[n-d]&&d<n)d++;
s+=d;
}
h+1;
cout<<h;
return 0;
}