1146: Eat Candy __zzuli-oj

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.