# bzoj1816 扑克牌

3 4
1 2 3

## Sample Output

3

50%的数据满足：2 < = n < = 5, 0 < = m < = 10^ 6, 0< = ci < = 200
100%的数据满足：2 < = n < = 50, 0 < = m, ci < = 500,000,000。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int maxn = 105;
int n,m,s,c[maxn];
void input(){
cin>>n>>m;
s = 0;
for(int i = 1;i <= n;i++){
scanf("%d",&c[i]);
if(s < c[i]) s = c[i];
}
s += m;
}
bool check(int t){
int add = 0;
for(int i = 1;i <= n;i++){
if(t - c[i] > 0) add += t - c[i];
if(t < add || m < add) return false;
}
return true;
}
void div(){
int lans = 0,rans = s,mans;
while(lans <= rans){
mans = (lans + rans) >> 1;
if(check(mans)){
lans = mans + 1;
}else{
rans = mans - 1;
}
}
if(check(mans))cout<<mans;
else cout<<mans-1;
}
int main(){
input();
div();
return 0;
}
View Code

add - j + i > i

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int maxn = 105;
int n,m,s,c[maxn];
void input(){
cin>>n>>m;
s = 0;
for(int i = 1;i <= n;i++){
scanf("%d",&c[i]);
if(s < c[i]) s = c[i];
}
s += m;
}
bool check(int t){
int add = t - c[1];
for(int i = 2;i <= n;i++){
if(c[i] < add || m < add) return false;
else{
if(t - c[i] > 0) add += t - c[i];
}
}
if(m < add) return false;
return true;
}
void div(){
int lans = 0,rans = s,mans;
while(lans <= rans){
mans = (lans + rans) >> 1;
if(check(mans)){
lans = mans + 1;
}else{
rans = mans - 1;
}
}
if(check(mans))cout<<mans;
else cout<<mans-1;
}
int main(){
input();
div();
return 0;
}
View Code
posted @ 2016-07-09 14:18  ACforever  阅读(202)  评论(0编辑  收藏  举报