1146: Eat candyTime limit: 1 Sec Memory limit: 128 MB
Submitted: 2418 Settlement: 1098
Submitted State [Discussion Version] [Propositional person: admin]
Topic Description
HOHO, finally from Speakless hand to win all the candy, is Gardon eat candy has a special hobby, is not like two consecutive to eat the same candy, like to eat first a kind of candy, next time to change a taste, eat a B kind of candy, so But Gardon does not know whether there is a candy order so that he can eat all the sweets. Please write a program to help you calculate.
input
The first line has an integer t, next T Group data, each group of data occupies 2 rows, the first row is an integer n (0 < n <= 1000000), indicating the type of candy. The second line is n, indicating the number of each candy mi (0 < mi <= 109). Output
For each set of data, the output line contains a "Yes" or "No". Sample Input
2
3
4 1 1
5
5 4 3 2 1
Sample Output
No
Yes
Tips
Source
#include <stdio.h>
int kinds[1000010];
int main (int argc, char** argv)
{
int t,n;
int i,j;
int max=0;
Long long sum=0;
scanf ("%d", &t);
while (t--)
{
sum=0;
max=0;
scanf ("%d", &n);
For (i=0 i<n; i++)
{
scanf ("%d", &kinds[i]);
if (Max<kinds[i])
max=kinds[i];
}
For (i=0 i<n; i++)
{
if (Kinds[i]<max)
sum+=kinds[i];
}
if (max-1>sum)
printf ("no\n");
else
printf ("yes\n");
}
return 0;
}
1146: Eat candy time limit: 1 Sec Memory limit: 128 MB
Submitted: 2418 Settlement: 1098
Submitted State [Discussion Version] [Propositional person: admin] Topic Description
HOHO, finally from Speakless hand to win all the candy, is Gardon eat candy has a special hobby, is not like two consecutive to eat the same candy, like to eat first a kind of candy, next time to change a taste, eat a B kind of candy, so But Gardon does not know whether there is a candy order so that he can eat all the sweets. Please write a program to help you calculate.
input
The first line has an integer t, next T Group data, each group of data occupies 2 rows, the first row is an integer n (0 < n <= 1000000), indicating the type of candy. The second line is n, indicating the number of each candy mi (0 < mi <= 109). Output
For each set of data, the output line contains a "Yes" or "No". Sample Input
2
3
4 1 1
5
5 4 3 2 1
Sample Output
No
Yes
Tips
Source