吃糖果 HDU - 1205 思维

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

input

2
3
4 1 1
5
5 4 3 2 1

output

No
Yes

code

//Siberian Squirrel
//#include<bits/stdc++.h>
//#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<set>
#include<string>

#define ACM_LOCAL

using namespace std;
typedef long long ll;

const double PI = acos(-1);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
const int UP = 1e2 + 10;

int a[N];

inline bool solve(int n, ll res = 0) {
    
    
    int maxx = 0;
    for(int i = 1; i <= n; ++ i) {
    
    
        scanf("%d", &a[i]);
        res += a[i];
        maxx = max(maxx, a[i]);
    }
    if(maxx - 1 <= res - maxx) return true;
    return false;
}

int main() {
    
    
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    int o = 1, n;
    scanf("%d", &o);
    while(o --) {
    
    
        scanf("%d", &n);
        printf("%s\n", solve(n)? "Yes": "No");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_46173805/article/details/113917107