Zero Array(CodeForces - 1201B )(思路)

30 篇文章 0 订阅

You are given an array a1,a2,…,ana1,a2,…,an.

In one operation you can choose two elements aiai and ajaj (i≠ji≠j) and decrease each of them by one.

You need to check whether it is possible to make all the elements equal to zero or not.

Input

The first line contains a single integer nn (2≤n≤1052≤n≤105) — the size of the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.

Output

Print "YES" if it is possible to make all elements zero, otherwise print "NO".

Examples

Input

4
1 1 2 2

Output

YES

Input

6
1 2 3 4 5 6

Output

NO

Note

In the first example, you can make all elements equal to zero in 33 operations:

  • Decrease a1a1 and a2a2,
  • Decrease a3a3 and a4a4,
  • Decrease a3a3 and a4a4

In the second example, one can show that it is impossible to make all elements equal to zero.

题意:这道题的意思是给出你n个数,让你每次从其中选出2个数,每次进行-1操作,问你能不能把每个数都减到0.

思路:好不巧。。这又是道思路题,卑微的我,一开始又去找那虚无缥缈的复杂规律了。后来,找到烦躁的我找着找着就想到,如果,给你的数的权值的和如果是偶数的话,那可能会正好减到0,也可能不会减到;如果和为奇数,那是不可能会减到0的。

之后,如果和为偶数的时候,我们判断一下和还有最大值的差值,如果这个差值比最大值还要大,那是完全可以把所有数减到0的,否则的话,是不能减到0的。

AC代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
const int maxx=0x3f3f3f3f;
using namespace std;
long long a[100010];
int main()
{
    long long n,sum=0;
    scanf("%lld",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);
        sum+=a[i];
    }
    sort(a+1,a+1+n);
    if(sum%2!=0)
        printf("NO\n");
    else
    {
        long long ans=sum-a[n];
        if(ans>=a[n])
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值