CDZSC_2015寒假新人(2)——数学 - G

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, 那么就可以保证存在。详见代码。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define LL long long
 5
 6 const int MAX = 1000024;
 7 int arr[MAX];
 8
 9 int main()
10 {
11 #ifdef CDZSC_OFFLINE
12     freopen("in.txt", "r", stdin);
13     freopen("out.txt", "w", stdout);
14 #endif
15     int n, t;
16     scanf("%d", &t);
17     while(t--)
18     {
19         scanf("%d", &n);
20         LL sum = 0;
21         for(int i = 0; i < n; i++)
22         {
23             scanf("%d", &arr[i]);
24             sum += arr[i];
25         }
26         std::sort(arr, arr + n);
27         sum -= arr[n - 1];
28         printf("%s\n", (sum >= (arr[n - 1] - 1)) ? "Yes" : "No");
29     }
30     return 0;
31 }

时间: 2024-07-28 18:41:32

CDZSC_2015寒假新人(2)——数学 - G的相关文章

CDZSC_2015寒假新人(2)——数学 - B

Description 求A^B的最后三位数表示的整数. 说明:A^B的含义是“A的B次方” Input 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理. Output 对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行. Sample Input 2 3 12 6 6789 10000 0 0 Sample Output 8 984 1 题解:直接相乘,会溢出,可以对一个10

CDZSC_2015寒假新人(2)——数学 - H

Description Sky从小喜欢奇特的东西,而且天生对数字特别敏感,一次偶然的机会,他发现了一个有趣的四位数2992,这个数,它的十进制数表示,其四位数字之和为2+9+9+2=22,它的十六进制数BB0,其四位数字之和也为22,同时它的十二进制数表示1894,其四位数字之和也为22,啊哈,真是巧啊.Sky非常喜欢这种四位数,由于他的发现,所以这里我们命名其为Sky数.但是要判断这样的数还是有点麻烦啊,那么现在请你帮忙来判断任何一个十进制的四位数,是不是Sky数吧. Input 输入含有一些

CDZSC_2015寒假新人(2)——数学 - A

Description The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105. Input Input will consist of multiple problem inst

CDZSC_2015寒假新人(2)——数学 - O

Description 当寒月还在读大一的时候,他在一本武林秘籍中(据后来考证,估计是计算机基础,狂汗-ing),发现了神奇的二进制数. 如果一个正整数m表示成二进制,它的位数为n(不包含前导0),寒月称它为一个n二进制数.所有的n二进制数中,1的总个数被称为n对应的月之数. 例如,3二进制数总共有4个,分别是4(100).5(101).6(110).7(111),他们中1的个数一共是1+2+2+3=8,所以3对应的月之数就是8. Input 给你一个整数T,表示输入数据的组数,接下来有T行,每

CDZSC_2015寒假新人(2)——数学 P

P - P Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description 有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b.若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c. Input 第一行输入一个n,表示有n组测试数据,接下来的n行,每行输入两个正整数a,b. Output 输出对应的c,每组测试数据占一行.

CDZSC_2015寒假新人(2)——数学 C

C - C Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first line of the

CDZSC_2015寒假新人(4)——搜索 G

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟

CDZSC_2015寒假新人(2)——数学 D

D - D Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2). Input Input consists of a sequence of line

CDZSC_2015寒假新人(1)——基础 G

Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first line of the input is a s