CodeForces - 1201B Zero Array

时间:2019-11-11
本文章向大家介绍CodeForces - 1201B Zero Array ,主要包括CodeForces - 1201B Zero Array 使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

You are given an array a1,a2,,ana1,a2,…,an.

In one operation you can choose two elements aiai and ajaj (iji≠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 (2n1052≤n≤105) — the size of the array.

The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109) — the elements of the array.

Output

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

Examples

Input
4
1 1 2 2
Output
YES
Input
6
1 2 3 4 5 6
Output
NO


题意:

给你n个数,你可以每次找到两个数并且让它们都减去1.问你可不可以到最后这n个数都变成0

题解:

首先我们可以确定,如果这些数的和是一个奇数的话,那么肯定输出NO。这n个数里面,如果每一次都对这n个数里面的最大值和第二大值进行减1操作。那么减到最后肯定可以全部减为0(前提就是:这n个数里面的最大值肯定要小于其他数之和)

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int main()
 7 {
 8     long long n,sum=0,a,maxx=0;
 9     scanf("%I64d",&n);
10     for(long long i=0;i<n;++i)
11     {
12         scanf("%I64d",&a);
13         sum+=a;
14         maxx=max(maxx,a);
15     }
16     if(sum-maxx>=maxx)
17     {
18         if(sum%2)
19             printf("NO\n");
20         else printf("YES\n");
21     }
22     else printf("NO\n");
23 }
View Code

原文地址:https://www.cnblogs.com/kongbursi-2292702937/p/11835839.html