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

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;
}
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值