Eat candy
Time limit:6000/3000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 30589 Accepted Submission (s): 8661
Problem Descriptionhoho, 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 don't know if there is a candy-eating order so he can 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 Input234 1 155 4 3 2 1
Sample Outputnoyes
HintHintplease Use function scanf Analysis: Find the largest, the largest between the MaxValue-1 gap, and then the rest (Sum-maxvalue) as long as the gap can be filled with Yes
1#include <iostream>2#include <cstring>3#include <algorithm>4#include <cstdio>5 6 using namespacestd;7 8 intMain ()9 {Ten intT,n; Onescanf"%d", &t); A while(t--) - { -scanf"%d", &n); the intA; - Long Longsum =0; - intMaxValue =0; - for(inti =1; I <= N; i++) + { -scanf"%d", &a); +Sum + =A; AMaxValue =Max (MaxValue, a); at } -Sum-=MaxValue; - if(Sum >= MaxValue-1) -printf"yes\n"); - Else -printf"no\n"); in - } to + return 0; -}View Code
HD1205 eating sweets (pigeon nest, drawer principle)