Hdu1205 吃糖果

75 篇文章 0 订阅

吃糖果



Problem Description
HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。
 

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
Hint
Hint
Please use function scanf
 

Author
Gardon
 

Source
 

Recommend
JGShining
 

————————————————————————————————————
思路:可以很清楚发现只要最大的数-1<=剩下的数求和就可以,否则就不行
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;


int main()
{
  int T,n;
  LL x;
  scanf("%d",&T);
  while(T--)
  {
      scanf("%d",&n);
      LL sum=0;
      LL mx=-1;
      for(int i=0;i<n;i++)
      {
          scanf("%lld",&x);
          mx=max(mx,x);
          sum+=x;
      }
      if(sum-mx>=mx-1)
        printf("Yes\n");
      else
        printf("No\n");

  }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值