1421: 吃糖果
1.描述
HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢连续两次吃一样的糖果,喜欢先吃一颗A种类的糖果,下一次换一种口味,吃一颗B种类的糖果,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。
输入
第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N(0 < N <= 1000000),表示糖果的种类。。第二行是N个数,表示每种糖果的数目Mi(0 < Mi <= 1000000)。
输出
对于每组数据,输出一行,包含一个"Yes"或者"No"。
样例输入
2
3
4 1 1
5
5 4 3 2 1
样例输出
No
Yes
2.代码
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
long long int n,i,j,m,max,x;
scanf("%lld",&n);
for(i=1; i<=n; i++)
{
long long int t=0;
scanf("%lld",&m);
scanf("%lld",&x);
max=x;
t=x;
for(j=1; j<m; j++)
{
scanf("%lld",&x);
max=x>max?x:max;
t+=x;
}
if(t-max+1>=max)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
return 0;
}
449

被折叠的 条评论
为什么被折叠?



