http://acm.hdu.edu.cn/showproblem.php?pid=1205
鸽巢原理
将题目糖果看作所需要的隔板,有n个糖果,根据鸽巢定理,就至少需要n-1个隔板;现在求出最大的糖果数,然后把其它剩余的糖果看作一个整体,看它是否大于最大糖果数-1这一个条件
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<iomanip>
using namespace std;
int main()
{
int Case ;
scanf( "%d" , &Case ) ;
__int64 n ;
while( Case-- )
{
scanf( "%I64u" , &n );
__int64 sum = 0 ;
__int64 max = -1 ;
while( n-- )
{
__int64 temp ;
scanf( "%I64u" ,&temp ) ;
sum += temp ;
if( max < temp )
max = temp ;
}
if( ( sum - max ) >= ( max - 1 ) )
printf( "Yes\n" ) ;
else
printf( "No\n" ) ;
}
return 0 ;
}