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;
}
相关推荐
SmartBrain1 分钟前
技术总结:VLLM部署Qwen3模型的详解
开发语言·人工智能·算法·vllm
weixin_477271694 分钟前
第四正:关键(马王堆帛书《老子》20)
人工智能·算法·图搜索算法
玄〤6 分钟前
枚举问题的两大利器:深度优先搜索(DFS)与下一个排列(Next Permutation)算法详解(Java版本)(漫画解析)
java·算法·深度优先·dfs
weixin_477271698 分钟前
第三正:结构(马王堆帛书《老子》2)
算法·图搜索算法
uesowys9 分钟前
算法开发指导-数据结构-Tree
数据结构·算法·
小冻梨6669 分钟前
ABC445 C - Sugoroku Destination题解
c++·算法·深度优先·图论·
啊阿狸不会拉杆17 分钟前
《计算机视觉:模型、学习和推理》第 6 章-视觉学习和推理
人工智能·学习·算法·机器学习·计算机视觉·生成模型·判别模型
道法自然|~20 分钟前
BugCTF猪圈密码
算法
52Hz11820 分钟前
力扣33.搜索旋转排序数组、153.寻找排序数组中的最小值
python·算法·leetcode
DeepModel22 分钟前
【回归算法】高斯过程回归详解
算法·回归