Hdu 1205 Eating Sweets (drawer principle)

Source: Internet
Author: User

Eat Candy Time limit:6000/3000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 24390 Accepted Submission (s): 6969


Problem Description HOHO, finally from Speakless hand to win all the candy, is Gardon eat candy when there is a special hobby, is not like the same candy put together to eat, like to eat first, the next time to eat another, so But Gardon did not know if there was a candy-eating order that allowed him to finish all the candies. Please write a program to help calculate.

Input first line has an integer t, the next T-group data, each group of data accounted for 2 rows, the first row is an integer n (0<n<=1000000), the second row is n number, indicating the number of n candies Mi (0<mi<=1000000).

Output for each set of data, outputs a line that contains a "Yes" or "No".

Sample Input

2 3 4 1 1 5 5 4 3 2 1
Sample Output
No Yes Hint Hint use function scanf


Test instructions is to give the number of n candies to eat candy requirements are the same kind of candy can not eat at the same time

You can find out which of these candies is the largest number of the most

Simulate to have a drawer put other n-1 kind of candy into this one drawer because an is the largest so the same drawer can not appear the same kind of candy so just make sure that there is a maximum of one drawer in the empty can

#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include < algorithm> #include <string.h> #include <string> #define EPS 1e-8 #define OP operator #define MOD 10009 # Define MAXN 1000010 #define INF 0x7fffffff #define for (I,A,B) for (int. i=a;i<=b;i++) #define FOV (I,A,B) for (int i=a;    i>=b;i--) #define REP (I,A,B) for (int i=a;i<b;i++) #define Rev. (I,A,B) for (int i=a-1;i>=b;i--) #define MEM (a,x)

memset (a,x,sizeof a) #define LL __int64 using namespace std;

ll A[MAXN];
    int main () {//freopen ("Ceshi.txt", "R", stdin);
    int TC;
    scanf ("%d", &AMP;TC);
        while (tc--) {int n;
        scanf ("%d", &n);
        ll Sum=0;
            for (int i=0;i<n;i++) {scanf ("%i64d", &a[i]);
        Sum+=a[i];
        } sort (a,a+n);
        SUM-=A[N-1];
        if (Sum+1>=a[n-1]) puts ("Yes");
    Else puts ("No");
} return 0; }




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.