HDU 1205

来源:互联网 发布:淘宝店铺发布产品 编辑:程序博客网 时间:2024/06/10 08:20
A - A
Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 1205

Description

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

Input

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

Output

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

Sample Input

234 1 155 4 3 2 1
 

Sample Output

NoYes

思路:找到规律。

AC代码:

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;int main(){int T;scanf("%d",&T);while(T--){__int64 n;scanf("%I64d",&n);__int64 judge=0,first=0;for(__int64 i=0;i<n;i++){__int64 temp;scanf("%I64d",&temp);first=max(first,temp);judge+=temp;}if(judge+1-first>=first)printf("Yes\n");elseprintf("No\n");}return 0;}


0 0
原创粉丝点击