Zero Array---思维题
1 second
256 megabytes
standard input
standard output
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.
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.
Print "YES" if it is possible to make all elements zero, otherwise print "NO".
4
1 1 2 2
YES
6
1 2 3 4 5 6
NO
In the first example, you can make all elements equal to zero in 33 operations:
- Decrease a1a1 and a2a2,
- Decrease a3a3 and a4a4,
- Decrease a3a3 and a4a4
In the second example, one can show that it is impossible to make all elements equal to zero.
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
ll num[100001],n;
//priority_queue<ll,vector<ll>,less<ll> > p;
int main(){
while(~scanf("%lld",&n)){
ll sum=0,max_k=-1;
for(ll i=1;i<=n;i++){
scanf("%lld",&num[i]);
sum+=num[i];
max_k=max(max_k,num[i]);
}
//如果总和不是偶数,或者最大值比总和的一半大,不能实现
if(sum%2==1||max_k>sum/2){
printf("NO\n");
continue;
}
else {
printf("YES\n");
continue;
}
}
return 0;
}
// /\ | / |**、
// / \ | / | \
// / \ |/ | / _____ ____ | /
// /------\ |\ |__/ / \ \ /\ / / \ | /
// / \ | \ | / \ \ / \ / /______\ |/
// / \ | \ | \ / \ / \ / \ |
// / \ | \ | \_____/ \/ \/ \_____ |
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//
Zero Array---思维题的更多相关文章
- CF949B A Leapfrog in the Array 思维题,推理
		题意: Dima是一名初级程序员. 在他的工作中,他经常不断地重复以下操作:从数组中删除每个第二个元素. 有一天,他对这个问题的解决方案感到厌倦,他提出了以下华丽的算法. 假设有一长度为2n的数组,最 ... 
- zoj 3778 Talented Chef(思维题)
		题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ... 
- cf A. Inna and Pink Pony(思维题)
		题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ... 
- ZOJ 3829 贪心 思维题
		http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ... 
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
		思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ... 
- C. Nice Garland  Codeforces Round #535 (Div. 3) 思维题
		C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ... 
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
		PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ... 
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
		UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ... 
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
		HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ... 
- cf796c 树形,思维题
		一开始以为是个树形dp,特地去学了..结果是个思维题 /* 树结构,设最大点权值为Max,则答案必在在区间[Max,Max+2] 证明ans <= Max+2 任取一个点作为根节点,那么去掉这个 ... 
随机推荐
- td中文字居中
			<style> .table_style{width: 100%;height: auto;} .table_style tr td{text-align: center;vertical ... 
- HDU 2176 取(m堆)石子游戏  —— (Nim博弈)
			如果yes的话要输出所有情况,一开始觉得挺难,想了一下也没什么. 每堆的个数^一下,答案不是0就是先取者必胜,那么对必胜态显然至少存在一种可能性使得当前局势变成必败的.只要任意选取一堆,把这堆的数目变 ... 
- python并发——从线程池获取返回值
			并发是快速处理大量相似任务的绝佳办法,但对于有返回值的方法,需要一个容器专门来存储每个进程处理完的结果 from multiprocessing import Pool import time #返回 ... 
- php多线程的概念
			来源:http://www.cnblogs.com/zhenbianshu/p/7978835.html 多线程 线程 首先说下线程: 线程(thread) 是操作系统能够进行运算调度的最小单位.它被 ... 
- linux中安装python
			1.首先切换目录 大型的软件一定要安装在/ opt中 规范 cd /opt 2.下载python3的源码 wget https://www.python.org/ftp/python/3.6.2/P ... 
- linux下如何单独编译设备树?
			答: make <vendor>/<device_name>.dtb 如: make freescale/fsl-1043a-rdb.dtb 
- Android提升Gradle编译速度或减少Gradle编译时间.md
			目录 Android如何提升Gradle编译速度或减少Gradle编译时间 最终优化方案 优化效果比对 将所有项目源码,各种缓存临时目录都移动到高性能SSD磁盘上 gradle.properties ... 
- openstack核心组件--neutron网络服务(4)
			一.neutron 介绍: Neutron 概述 传统的网络管理方式很大程度上依赖于管理员手工配置和维护各种网络硬件设备:而云环境下的网络已经变得非常复杂,特别是在多租户场景里,用户随时都可能需要 ... 
- 由DBCursor的“can't switch cursor access methods”异常引发的思考
			先谈谈我是怎么用的: DBCollection dbcollection = XXXXXXXXXX(); //连接mongo DBCursor dbCursor = mergeVideoDB.find ... 
- Java泛型(2):泛型接口
			泛型不仅可以在类上实现,也可以在接口上实现.JDK中[Iterable<T> <-- Collection<E> <-- List<E>/Queue&l ... 
