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;
}
相关推荐
动词ing14 分钟前
【C语言】自定义函数+指针入门
c语言·开发语言·算法
重生之后端学习29 分钟前
283. 移动零[简单]✅
开发语言·数据结构·算法·leetcode·职场和发展
一只小小的芙厨1 小时前
基础数论总结
笔记·学习·算法
夜不会漫长2 小时前
C++入门(1)
开发语言·c++·算法
wen_zhufeng3 小时前
IndexTTS 2.5 技术报告
人工智能·算法·机器学习
大熊背4 小时前
树莓派相机自动白平衡详解(四)
算法·树莓派·白平衡·isppipeline
一米阳光86614 小时前
软考(中级)软件设计师核心笔记(9)算法——背包问题
笔记·算法·职场发展·软考·软件设计师·中级职称
晚风醉蝶4 小时前
1-11-奇偶排序-OddEvenSort
java·数据结构·算法
旖旎夜光4 小时前
LeetCode 852:山脉数组的峰顶索引(二分查找) —— 题解
数据结构·c++·算法·leetcode·二分查找
..Dauntless..4 小时前
【C++】继承——基类和派生类的配合
开发语言·c++·算法