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;
}
相关推荐
笨笨饿2 分钟前
80_聊聊SPI以及它们的变体
linux·c语言·网络·stm32·单片机·算法·个人开发
Ricardo-Yang3 分钟前
使用GEE以及LandSat8植被指数NDVI计算
python·深度学习·神经网络·算法·视觉检测
sheeta19988 分钟前
LeetCode 每日一题笔记 日期:2026.05.12 题目:1665. 完成所有任务的最少初始能量
笔记·算法·leetcode
khalil10209 分钟前
代码随想录算法训练营Day-49 图论01 | 图论理论基础、深搜理论基础、98. 所有可达路径、广搜理论基础
c++·算法·leetcode·深度优先·图论
Chase_______18 分钟前
【算法】删除子数组的最大得分 & 最多 K 个重复元素的最长子数组——不定长滑动窗口与哈希频率约束
算法·哈希算法
fie888930 分钟前
城市环境下车辆目标跟踪算法 MATLAB 实现
算法·matlab·目标跟踪
tryCbest32 分钟前
软考 - 排序算法
算法·排序算法
AKA__Zas43 分钟前
芝士算法(双指针篇 1.0)
java·算法·学习方法
吃着火锅x唱着歌1 小时前
LeetCode 726.原子的数量
linux·算法·leetcode
君义_noip1 小时前
CSP-S 2025 提高级 第一轮(初赛) 阅读程序(3)
c++·算法·信息学奥赛·csp-s 初赛