D - Zero Array

You are given an array a_1, a_2, \ldots, a_na1​,a2​,...,an​.

In one operation you can choose two elements a_iai​ and a_jaj​ (i \ne 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 \le n \le 10^52≤n≤105) --- the size of the array.

The second line contains nn integers a_1, a_2, \ldots, a_na1​,a2​,...,an​ (1 \le a_i \le 10^91≤ai​≤109) --- the elements of the array.

Output

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

Sample 1

Inputcopy Outputcopy
4 1 1 2 2 YES

Sample 2

Inputcopy Outputcopy
6 1 2 3 4 5 6 NO

Note

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

  • Decrease a_1a1 and a_2a2,
  • Decrease a_3a3 and a_4a4,
  • Decrease a_3a3 and a_4a4

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

复制代码
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n;
ll sum = 0;
int main()
{
	ll maxnum = 0;
	cin >> n;
	for (ll i = 0; i < n; i++)
	{
		ll num;
		cin >> num;
		sum += num;
		maxnum = max(maxnum, num);
	}
	//因为是成对成对的减少,所以总数首先是偶数。其次还要满足最大的数小于等于总数的一半,这样才能保证最大的数消去
	if (sum % 2 == 0&&maxnum <= sum / 2) cout << "YES" << endl;
	else cout << "NO" << endl;
}
相关推荐
我想进大厂16 分钟前
图论---朴素Prim(稠密图)
数据结构·c++·算法·图论
我想进大厂20 分钟前
图论---Bellman-Ford算法
数据结构·c++·算法·图论
AIGC大时代23 分钟前
高效使用DeepSeek对“情境+ 对象 +问题“型课题进行开题!
数据库·人工智能·算法·aigc·智能写作·deepseek
CODE_RabbitV1 小时前
【深度强化学习 DRL 快速实践】近端策略优化 (PPO)
算法
Wendy_robot2 小时前
【滑动窗口+哈希表/数组记录】Leetcode 438. 找到字符串中所有字母异位词
c++·算法·leetcode
程序员-King.2 小时前
day49—双指针+贪心—验证回文串(LeetCode-680)
算法·leetcode·贪心算法·双指针
转基因2 小时前
Codeforces Round 1020 (Div. 3)(题解ABCDEF)
数据结构·c++·算法
我想进大厂3 小时前
图论---Kruskal(稀疏图)
数据结构·c++·算法·图论
@Aurora.4 小时前
数据结构手撕--【二叉树】
数据结构·算法
victd4 小时前
什么是AutoRec?
算法