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;
}
相关推荐
qeen873 分钟前
【算法笔记】差分与经典例题解析
c语言·c++·笔记·学习·算法·差分
kronos.荒8 分钟前
动态规划——整数拆分(python)
python·算法·动态规划
cici1587415 分钟前
基于Koopman模型预测控制的非线性流控制数据驱动框架
算法
6Hzlia16 分钟前
【Hot 100 刷题计划】 LeetCode 416. 分割等和子集 | C++ 0-1背包 1D空间极致优化
c++·算法·leetcode
穿条秋裤到处跑18 分钟前
每日一道leetcode(2026.04.21):执行交换操作后的最小汉明距离
java·算法·leetcode
Tina学编程19 分钟前
算法训练Day10 | LeetCode 169 多数元素
算法·leetcode
sheeta199827 分钟前
LeetCode 每日一题笔记 日期:2026.04.22 题目:2452. 距离字典两次编辑以内的单词
笔记·算法·leetcode
ZPC821034 分钟前
nmtui
人工智能·算法·机器人
_深海凉_36 分钟前
LeetCode热题100-全排列
算法·leetcode·职场和发展
programhelp_38 分钟前
TikTok 26 Summer SDE Intern 面经分享|两轮技术面 + Timeline 复盘
数据结构·经验分享·算法·面试