标签:
二分答案。
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,n) for(int i=1;i<=n;i++) const int inf=0x7f7f7f7f; int c[55],n,m; bool check(int x){ int cnt=min(x,m); rep(i,n) if(c[i]<x) { cnt-=x-c[i]; if(cnt<0) return false; } return true; } void work(){ int l=0,r=inf,ans; while(l<=r){ int mid=(l+r)>>1; if(check(mid)) ans=mid,l=mid+1; else r=mid-1; } printf("%d\n",ans); } int main(){; scanf("%d%d",&n,&m); rep(i,n) scanf("%d",&c[i]); work();return 0; }
标签:
原文地址:http://www.cnblogs.com/fighting-to-the-end/p/5674924.html