# BZOJ 1816 扑克牌(二分)

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-9
# define MOD 9999973
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
int Scan() {
int res=0, flag=0;
char ch;
if((ch=getchar())=='-') flag=1;
else if(ch>='0'&&ch<='9') res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')  res=res*10+(ch-'0');
return flag?-res:res;
}
void Out(int a) {
if(a<0) {putchar('-'); a=-a;}
if(a>=10) Out(a/10);
putchar(a%10+'0');
}
const int N=55;
//Code begin...

int a[N], n, m;

bool check(int x){
LL res=0;
FOR(i,1,n) {
if (a[i]>=x) continue;
res+=(x-a[i]);
}
return res<=min(m,x);
}
int main ()
{
int ma=0;
scanf("%d%d",&n,&m);
FOR(i,1,n) scanf("%d",a+i), ma=max(ma,a[i]);
int l=0, r=ma+m+1, mid;
while (l<r) {
mid=(l+r)>>1;
if (l==mid) break;
if (check(mid)) l=mid;
else r=mid;
}
printf("%d\n",l);
return 0;
}
View Code

posted @ 2017-03-25 20:45  free-loop  阅读(272)  评论(0编辑  收藏  举报