rt,50pts,code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,a[1000100],sum,s[1000100];
bool check(int x){
int pos=lower_bound(a+1,a+1+n,x+1)-a;
int sum=(pos-1)*(x+1)-s[pos-1];
if(sum<=k*x){
return true;
}
else{
return false;
}
}
signed main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=(a[i]-1);
}
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
s[i]=s[i-1]+a[i];
}
int l=0,r=1e12;
while(l<r){
int mid=(l+r)/2;
if(check(mid)){
l=mid;
}
else{
r=mid-1;
}
}
cout<<l;
return 0;
}