sort排序之后 不断查找最小能满足的值即可
#include <bits/stdc++.h>
using namespace std;
long long n,m,temp;
vector<long long> tree;
bool cheak(long long mid){
long long sum=0;
for(long long i=0;i<tree.size();i++){
if(tree[i]>mid)sum+=tree[i]-mid;
}
if(sum>=m)return true;
else return false;
}
int main() {
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>temp;
tree.push_back(temp);
}
sort(tree.begin(),tree.end());
long long l=tree.front(),r=tree.back();
while(l<r){
long long mid=(l+r)/2+1;
if(cheak(mid))l=mid;
else r=mid-1;
}
cout<<r;
return 0;
}