You are given an array a1,a2,…,an�1,�2,…,��.
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≤1052≤�≤105) — the size of the array.
The second line contains n� integers a1,a2,…,an�1,�2,…,�� (1≤ai≤1091≤��≤109) — the elements of the array.
Output
Print "YES" if it is possible to make all elements zero, otherwise print "NO".
Examples
input
Copy
4 1 1 2 2
output
Copy
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 a1�1 and a2�2,
- Decrease a3�3 and a4�4,
- Decrease a3�3 and a4�4
In the second example, one can show that it is impossible to make all elements equal to zero.
题目大意:
给n个堆,每次选两个堆,各减一,问最后能不能让所有的堆变成0。
思路:
记录最大值,防止其他堆之和小于最大值导致无法全变0的被判断成可以全变0。
AC代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl "\n" void solve(){ ll x,z,mx=0,sum=0; cin >> x; for(ll i = 0 ; i < x ; i ++){ cin >> z; sum+=z; mx=max(mx,z); } if(sum%2 == 0 && mx <= sum/2)cout << "YES" << endl; else cout << "NO" << endl; return; } int main() { ll t=1;//cin >> t; while(t--)solve(); return 0; }