3、9、10样例没过
#include<bits/stdc++.h>
using namespace std;
int tree[1000010];
long long N,M;
bool judge(int h){
int sum=0;
for(int i=1;i<=N;i++){
if(tree[i]>h){
sum+=(tree[i]-h);
}
}
if(sum>=M){
return true;
}else{
return false;
}
}
int main(){
cin>>N>>M;
int max=0;
for(int i=1;i<=N;i++){
cin>>tree[i];
if(tree[i]>max){
max=tree[i];
}
}
long long low=1,high=max;
while(low<high){
int mid=(low+high+1)/2;
if(judge(mid)){
low=mid;
}else{
high=mid-1;
}
}
cout<<low;
return 0;
}