乐逍遥xwl

导航

Codeforces Round #577 (Div. 2) B - Zero Array

Codeforces Round #577 (Div. 2)

 

B - Zero Array

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

In one operation you can choose two elements ai and aj (i≠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 n (2≤n≤105) — the size of the array.

The second line contains n integers a1,a2,…,an (1≤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 3 operations:

  • Decrease a1 and a2,
  • Decrease a3 and a4,
  • Decrease a3 and a4

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

 

题意:题目意思是给你n个数,你可以进行任意次操作:对序列里的两个数都减一,

问你最后能不能把序列n个数都变成0。

思路:显然如果n个数的总和是奇数,肯定不能把n个数都变0。

还有就是序列中最大的数比总和的一半还大,即最大值的两倍大于总和,

这也是不行的,因为就算你拿另外n-1个数对最大值去操作,最后这个数还是不会变0,

然后其他情况都是可以的。

 

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<map>
 7 #include<set>
 8 #include<vector>
 9 #include<queue>
10 #include<list>
11 //#include<unordered_map>
12 #include<stack>
13 using namespace std;
14 #define ll long long 
15 const int mod=1e9+7;
16 const int inf=1e9+7;
17  
18 const int maxn=1e5+10;
19  
20 int main()
21 {
22     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
23     
24     int n;
25     cin>>n;
26     ll int num;
27     ll int maxx=-1,sum;
28     for(int i=0;i<n;i++)
29     {
30         cin>>num;
31         sum+=num;
32         
33         if(num>maxx)
34             maxx=num;
35     }
36     
37     if(sum&1||maxx*2>sum)
38         return cout<<"NO"<<endl,0;
39     else
40         return cout<<"YES"<<endl,0;
41     
42     return 0;
43 }

 

posted on 2019-08-05 22:24  乐逍遥xwl  阅读(507)  评论(0编辑  收藏  举报