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 (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
4
1 1 2 2
YES
6
1 2 3 4 5 6
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的更多相关文章
- Codeforces 482B Interesting Array(线段树)
题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...
- Codeforces 1077C Good Array 坑 C
Codeforces 1077C Good Array https://vjudge.net/problem/CodeForces-1077C 题目: Let's call an array good ...
- codeforces 482B. Interesting Array【线段树区间更新】
题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...
- codeforces 407C Curious Array
codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...
- codeforces 797 E. Array Queries【dp,暴力】
题目链接:codeforces 797 E. Array Queries 题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...
- codeforces 86D : Powerful array
Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...
- Codeforces 660A. Co-prime Array 最大公约数
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces ---596B--Wilbur and Array(贪心模拟)
Wilbur and Array Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Su ...
- Codeforces 722C. Destroying Array
C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- 转载 - Ubuntu源改国内源 与 批量更改ubuntu机器apt源
change_apt_source.sh # !/bin/bash # 备份原来的源文件 cp /etc/apt/sources.list /etc/apt/sources.list.bak # 获取 ...
- Loadrunner参数化数据配置与更新方式
之前遇到过一种情况,对脚本进行并发测试时,脚本没有报错,但是有丢失的事物,与开发配合检查确定不是代码的问题,然后检查脚本,更换参数化数据配置与更新方式,问题解决.现在对参数化数据配置和更新方式进行总结 ...
- 推荐大家去撸60元的阿里云ACA DevOps认证
要试题的右边扫码支付10元,私聊博客哈,说出你微信号,留下邮箱,发你邮箱Pdf文件,这么便宜拿证!!
- (01)-Python3之--字符串操作
1.字符串切片取值 字符串的取值通过索引来读取,从0开始. 取区间值如下:字符串变量名[起始索引:结束索引].包含起始,但不包含结束.例如: str_my = "hello,python!我 ...
- IE双击打不开解决办法
方法1 [百度电脑专家]一键修复 建议下载并安装[百度电脑专家],官网:http://zhuanjia.baidu.com .打开[百度电脑专家],在搜索框内输入"IE修复",在搜 ...
- httpd反向代理实践(一)
div.example { background-color: rgba(229, 236, 243, 1); color: rgba(0, 0, 0, 1); padding: 0.5em; mar ...
- Hash Map集合和Hash Set集合
HashMap集合的使用 1.1.每个集合对象的创建(new) 1.2.从集合中添加元素 1.3.从集合中取出某个元素 1.4.遍历集合 public class HashMapTest { publ ...
- bzoj 2038(莫队算法)
2038: [2009国家集训队]小Z的袜子(hose) 时间限制: 20 Sec 内存限制: 259 MB 题目描述 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来 ...
- HDU1814和平委员会
题目大意: 有n对的人,编号从1-2*n,m对的人之间互相不喜欢,每对人中必徐选1个人加入和平委员会,求字典序最小的解 -------------------------------- 2-SAT问题 ...
- Eslint错误提示
"Missing semicolon." : "缺少分号.","Use the function form of \"use strict\ ...