CF 1042A Benches——二分答案(水题)
题目:http://codeforces.com/problemset/problem/1042/A
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=105; int n,m,a[N],ans,mx; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); mx=max(mx,a[i]); } int l=mx,r=mx+m; while(l<=r) { int mid=l+r>>1,sum=0; for(int i=1;i<=n;i++) sum+=mid-a[i]; if(sum>=m)ans=mid,r=mid-1; else l=mid+1; } printf("%d %d\n",ans,mx+m); return 0; }