传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1816
一张图表示我wa了三次的心情
Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,m;
LL a[55];
bool ok(LL x){
int t=min(m,x);
for(int i=1;i<=n;i++){
t-=(x-a[i])*(x>=a[i]);
if(t<0)return false;
}return true;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
int l=1,r=1e9;
while(l<r){
int mid=(l+r)>>1;
if(ok(mid))
l=mid+1;
else r=mid;
}cout<<l-1<<endl;
return 0;
}