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;
}
相关推荐
生态学者8 小时前
Global Change Biology | 森林越“步调一致”,反而越怕干旱?树木生长与叶片活动的同步之谜
大数据·人工智能·算法·r语言·微信公众平台
lsswear9 小时前
Agent 框架新手入门与实战部署指南
大数据·人工智能·算法
Data analyse45610 小时前
rnweb 回放数据量太大怎么办?分片存储与断点续传的实现思路
前端·网络·算法·数据分析
Navigator_Z12 小时前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
Nil20812 小时前
leetcode 64最小路径和
算法·leetcode·职场和发展
光影少年12 小时前
AI Agent、自动化与未来工作
人工智能·算法·架构
牧羊人.33313 小时前
计算机视觉基础 第16章|EigenFace,FisherFace,LBPH传统人脸识别算法
人工智能·算法·计算机视觉
Nil20813 小时前
leetcode 72编辑距离
算法·leetcode·职场和发展
神工坊13 小时前
技术分享︱SIMFORGE HSF® 网格加密与热点加速技术实践
算法·hpc·网格·cae·工程仿真·数值引擎·samr
CV@CV13 小时前
世界模型与智能体协同推理逻辑
人工智能·算法·边缘计算·量子计算·具身智能