鸽笼原理--hdu1205吃糖果


Problem Description
HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。



Input
第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N0<N<=1000000),第二行是N个数,表示N种糖果的数目Mi(0<Mi<=1000000)。



Output
对于每组数据,输出一行,包含一个"Yes"或者"No"。



Sample Input
2
3
4 1 1
5
5 4 3 2 1


Sample Output
No
Yes

qwq
很好想
考虑有n种糖果,那么每种糖果的数量都不能超过除这种糖果外其它糖果数量总和+1。
例如,最极端的情况为:ABABABABABA 其中A表示一种糖果,B表示其它糖果。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define LL long long
#define maxn 1000005
using namespace std;
int t,n,a[maxn],ans;
LL sum;

int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        sum=0;
        for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
        sort(a+1,a+n+1);
        if(a[n]<=sum-a[n]+1) printf("Yes\n");
        else printf("No\n");
    }
}

猜你喜欢

转载自blog.csdn.net/sizeof_you/article/details/80767839