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

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

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤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 }

CodeForces - 1201B Zero Array的更多相关文章

  1. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  2. Codeforces 1077C Good Array 坑 C

    Codeforces 1077C Good Array https://vjudge.net/problem/CodeForces-1077C 题目: Let's call an array good ...

  3. codeforces 482B. Interesting Array【线段树区间更新】

    题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...

  4. codeforces 407C Curious Array

    codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...

  5. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  6. codeforces 86D : Powerful array

    Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...

  7. Codeforces 660A. Co-prime Array 最大公约数

    A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. CodeForces ---596B--Wilbur and Array(贪心模拟)

    Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Su ...

  9. Codeforces 722C. Destroying Array

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. 温故而知新--day2

    温故而知新--day2 类 类与对象 类是一个抽象的概念,是指对现实生活中一类具有共同特征的事物的抽象.其实列化后称为对象.类里面由类属性组成,类属性可以分为数据属性和函数属性(函数属性又称为类方法) ...

  2. InheritableThreadlocal使用问题排查

    背景 在做一个微服务系统的时候,我们的参数一般都是接在通过方法定义来进行传递的,类似这样 public void xxx(Param p, ...){ // do something } 然后这时有个 ...

  3. spring boot gateway 过滤器的执行顺序

    前言 学习官方文档,发现对于过滤器有分为三类 默认过滤器 自定义过滤 全局过滤器 于是就有一个疑问,关于这些过滤器的访问顺序是怎样的,今天就以一个demo来进行测试 准备阶段 过滤器工厂类 以此为模板 ...

  4. CVE-2019-15107_webmin漏洞复现

    一.漏洞描述 Webmin的是一个用于管理类Unix的系统的管理配置工具,具有网络页面.在其找回密码页面中,存在一处无需权限的命令注入漏洞,通过这个漏洞攻击者即可以执行任意系统命令.它已知在端口100 ...

  5. 与HBase对比,Cassandra的优势特性是什么?

    在1月9日Cassandra中文社区开年活动开始之前的闲聊时间,活动的四位嘉宾就"HBase和Cassandra的对比"这一话题展开了讨论.   总的来说,HBase和Cassan ...

  6. 【Python】国内pip节点

    pip在国内使用国内节点: http://pypi.douban.com/simple 现在已经无法使用了,新版的python3需要使用https://pypi.douban.com/simple/ ...

  7. kubernets集群的安全防护(下)

    一   集群角色以及集群角色绑定 1.1  前面我们提到过角色以及角色绑定,那么现在为什么会出现集群级别的角色以及角色绑定,作用有如下所示 我们如果需要在所有的命名的空间创建某个角色或者角色绑定的时候 ...

  8. 集成多种协议、用于 USBC 端口的快充协议芯片IP2723

    1. 特性  快充规格  集成 QC4/QC4+输出快充协议 - 兼容 QC2.0/QC3.0 - 支持 Class B 电压等级  集成 FCP 输出快充协议  集成 SCP 输出快充协议  集成 ...

  9. 全栈性能测试修炼宝典-JMeter实战笔记(一)

    了解性能测试 性能测试不仅能够定位.分析问题,还要把握系统性能变化趋势:性能测试工程师能够帮助解决性能问题,搞定测试过程中的各种不合理配置,给出专业的优化建议. 第一章 性能方向职业发展 软件测试职业 ...

  10. 陈思淼:阿里6个月重写Lazada,再造“淘宝”的技术总结

    小结: 1. 所谓的中台技术,就是从 IDC,网络,机房,操作系统,中间件,数据库,算法平台,数据平台,计算平台,到业务平台,每一层都有清晰的定义和技术产品. 具体来看,首先,集团技术的分层和每层的产 ...