【J ECJTU_ACM 11级队员2012年暑假训练赛(2)】

J - J
Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

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

Input

第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N(0<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

Hint

Hint
Please use function scanf



 1 // Project name : J
 2 // File name    : main.cpp
 3 // Author       : Izumu
 4 // Date & Time  : Tue Jul 10 12:41:53 2012
 5 
 6 
 7 #include <iostream>
 8 #include <stdio.h>
 9 #include <string>
10 #include <cmath>
11 using namespace std;
12 
13 int main()
14 {
15     int t;
16     scanf("%d", &t);
17     while (t--)
18     {
19         int n;
20         scanf("%d", &n);
21 
22         int sum = 0;
23         int max = 0;
24         for (int i = 0; i < n; i++)
25         {
26             int tmp;
27             scanf("%d", &tmp);
28             sum += tmp;
29             if (tmp > max)
30             {
31                 max = tmp;
32             }
33         }
34 
35         sum -= max;
36 
37         if (sum >= max)
38         {
39             printf("Yes\n");
40         }
41         else
42         {
43             printf("No\n");
44         }
45 
46 
47     }
48 
49     return 0;
50 }
51 // end 
52 // ism 
原文地址:https://www.cnblogs.com/ismdeep/p/2584788.html