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;
}
相关推荐
YuK.W20 分钟前
Leetcode100: 94.二叉树中序遍历、104.二叉树最大深度、226.翻转二叉树
java·算法·leetcode·二叉树
气泡音人声分离1 小时前
技术解析|均衡器(EQ)工作原理与实操指南:从频率拆分到听感优化
算法·均衡器·音频剪辑
weixin_413063212 小时前
复现 MatchED 边缘检测模型(单张图片重复8次,训练200 epoch)
python·算法·计算机视觉·边缘检测模型
2601_962440842 小时前
计算机毕业设计之jsp教室管理系统
java·开发语言·笔记·分布式·算法·课程设计·推荐算法
AI视频剪辑官2 小时前
播客切片工具选型核心评价维度
网络·人工智能·算法
复杂网络4 小时前
AI 不睡觉,但它比你更会做实验
算法
贵慜_Derek5 小时前
MAI-04|干净数据在工程上意味着什么:MAI 预训练数据治理
人工智能·算法·llm
想吃火锅10056 小时前
【leetcode】146.LRU缓存js
算法·leetcode·缓存
春日见7 小时前
E2E自驾JD理解
人工智能·深度学习·算法·microsoft·transformer