14行代码AC_Zero Array(思维)

立志用更少的代码做更高效的表达


You are given an array a1,a2,…,an.In one operation you can choose two elements ai and aj (i≠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 n (2≤n≤105) — the size of the array.The second line contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array.

Output
Print “YES” if it is possible to make all elements zero, otherwise print “NO”.

Input
4
1 1 2 2

Output
YES

Input
6
1 2 3 4 5 6

Output
NO


思路: 考查思维,判断和是否是偶数或最大值大于和的一半。


代码展示

#include<bits/stdc++.h>
using namespace std;
int main() {
	long long n; while(cin>>n) {
		long long sum = 0;
		long long Max = -1;
		for(int i = 0; i < n; i++) {
			long long x; cin>>x;
			sum += x;
			Max = max(Max, x);
		}
		cout << (sum%2==1||Max>sum/2 ? "NO" : "YES") << '\n';
	}
return 0; }

每日一句

先努力让自己发光,对的人才能迎着光而来。

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 像素格子 设计师:CSDN官方博客 返回首页