直接二分答案然后贪心验证:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define db double
#define sg string
#define ll long long
#define rel(i,x,y) for(ll i=(x);i<(y);i++)
#define rep(i,x,y) for(ll i=(x);i<=(y);i++)
#define red(i,x,y) for(ll i=(x);i>=(y);i--)
using namespace std;
const ll N=3e5+5;
const ll Inf=1e18;
ll n,m,c[N];
inline ll read() {
ll x=0;char ch=getchar();bool f=0;
while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?-x:x;
}
bool check(ll x) {
ll ret=min(m,x);
rep(i,1,n) if(c[i]<x) {
ret-=max(x-c[i],0ll);
if(ret<0) return false;
}
return true;
}
int main() {
n=read(),m=read();
rep(i,1,n) c[i]=read();
ll ans,l=0,r=Inf;
while(l<=r) {
ll mid=l+r>>1;
if(check(mid)) ans=mid,l=mid+1;
else r=mid-1;
}
printf("%lld\n",ans);
return 0;
}