题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1816
二分即可,WA了N次说明我还是实在太弱了。。。
代码:
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std ;
#define rep( i , x ) for ( int i = 0 ; i ++ < x ; )
const int maxn = 55 ;
int l = 0 , r = 1000000000 , a[ maxn ] , n , m , k , s ;
int main( ) {
scanf( "%d%d" , &n , &k ) ;
rep( i , n ) scanf( "%d" , a + i ) ;
while ( r - l > 1 ) {
s = min( m = ( l + r ) >> 1 , k ) ;
rep( i , n ) if ( a[ i ] < m ) {
if ( ( s -= ( m - a[ i ] ) ) < 0 ) break ;
}
if ( s < 0 ) r = m ; else l = m ;
}
printf( "%d\n" , l ) ;
return 0 ;
}