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;
}