吃糖果 HDU

来源:互联网 发布:五种常用的网络协议 编辑:程序博客网 时间:2024/06/05 09:27

Description

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

Input

第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N(0

Output

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

Sample Input

2
3
4 1 1
5
5 4 3 2 1

Sample Output

No
Yes

Hint

题意

让所有的糖果加起来 然后减去最大种类的糖果数 如果这个值和最大种类的糖果数少2 说明一定会取同种类糖果数 不满足条件

题解:

AC代码

#include <cstdio>#include <map>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;LL a[1000000];int main(){    int t;    scanf("%d",&t);    while (t--){        int n;        scanf("%d",&n);        LL mx = -1;        LL sum = 0;        for (int i = 0;i < n; ++i){            scanf("%d",&a[i]);            mx = max(mx,a[i]);            sum +=a[i];        }        if (sum-mx+1>=mx) printf("Yes\n");        else printf("No\n");    }    return 0;}