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
Please use function scanf
解法:
最多的那一堆糖果有n个,只需要有n-1个其它的糖果间隔开来就好了
代码:
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1111111];
void deal(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int bj=1;
long long sum=0;
for(int i=0;i<n-1;i++){
sum+=a[i];
}
if(sum>=a[n-1]-1) printf("Yes\n");
else
printf("No\n");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
deal();
return 0;
}
原文:http://www.cnblogs.com/xfww/p/7855966.html