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;
}
相关推荐
一切皆是因缘际会7 小时前
频域特征解构底层机理与双域融合鉴伪算法优化
人工智能·算法·ai·架构
Smilecoc7 小时前
决策树(三):剪枝
算法·决策树·剪枝
bIo7lyA8v7 小时前
算法性能建模的数值方法与误差分析的技术8
算法
Smilecoc7 小时前
决策树(四):决策树实战之鸢尾花分类
算法·决策树·分类
-Thinker7 小时前
【无标题】
java·开发语言·算法·图搜索
数据仓库搬砖人7 小时前
DBSCAN 原理深度解析:从聚类算法到风控团伙识别的实战指南
算法
凡人叶枫7 小时前
Effective C++ 条款24:若所有参数皆须要类型转换,请为此采用 non-member 函数
linux·前端·c++·算法·嵌入式开发
洛水水7 小时前
【力扣100题】87.只出现一次的数字
数据结构·算法·leetcode
HZ·湘怡7 小时前
排序算法之希尔排序(2)--菜鸟先飞
数据结构·算法·排序算法·希尔排序
乐观勇敢坚强的老彭7 小时前
2026全国青少年信息素养大赛(Python小学组)复赛复习讲义
python·算法·数学建模