BZOJ 1816: [Cqoi2010]扑克牌( 二分答案 )

------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>

#define rep( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )

using namespace std;

const int maxn = 50 + 5;

int c[ maxn ];
int n , m;

bool ok( int x ) {
int cnt = min( m , x );
rep( i , n ) if( c[ i ] < x ) {
cnt -= x - c[ i ];
if( cnt < 0 ) return false;
}
return true;
}

int main() {
cin >> n >> m;
rep( i , n ) {
scanf( "%d" , &c[ i ] );
}
int ans = 0;
int l = 0 , r = 0x7fffffff;
while( l <= r ) {
int m = ( l + r ) >> 1;
if( ok( m ) )
ans = m , l = m + 1;
else
r = m - 1;
}
cout << ans << "\n";
return 0;
}

------------------------------------------------------------------------

1816: [Cqoi2010]扑克牌

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1459  Solved: 560
[Submit][Status][Discuss]

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。

Source

posted @ 2015-05-28 22:04  JSZX11556  阅读(285)  评论(0编辑  收藏  举报