题目:http://codeforces.com/problemset/problem/1042/A
代码如下:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define mid ((l+r)>>1) using namespace std; int const maxn=105; int n,m,a[maxn],ans,mx; bool ck(int x) { int ret=0; for(int i=1;i<=n;i++)ret+=x-a[i]; return (ret>=m); } 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) { if(ck(mid))ans=mid,r=mid-1; else l=mid+1; } printf("%d %d ",ans,mx+m); return 0; }