1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #include <bits/stdc++.h> using namespace std; int n,m; long long a[1000005],ans; inline bool check(long long d){ long long cnt=0; for (int i=1;i<=n;i++)cnt+=max(a[i]-d,(long long)0); return cnt>=m; } int main(){ scanf("%d%d",&n,&m); long long l=1,r=0,mid; for (int i=1;i<=n;i++)scanf("%lld",&a[i]),r=max(r,a[i]); while(l<=r){ mid=(l+r)>>1; if (check(mid))ans=max(ans,mid),l=mid+1; else r=mid-1; } printf("%lld",ans); }
|