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 ...
随机推荐
- DHCP最佳实践(一)
这是Windows DHCP最佳实践和技巧的最终指南. 如果您有任何最佳做法或技巧,请在下面的评论中发布它们. 在本指南(一)中,我将分享以下DHCP最佳实践和技巧. 不要将DHCP放在您的域控制器上 ...
- linux之curl工具
curl是一个利用URL语法在命令行下工作的文件传输工具,作用是发出网络请求,然后获取数据:它支持文件的上传和下载:支持多种通信协议. 一.查看网页源码 直接在 curl 命令后加上网址,默认会发送 ...
- 【Samba】共享服务器的搭建和相关权限设置
1.查看防护墙 [root@zhang~ ]# /etc/init.d/iptables status iptables:Firewall is not running. 如果没有关闭的话将他 ...
- 【ASM】查看ASM磁盘组剩余容量和总容量
col total_size for a10; col free_size for a20; select name,total_mb/1024 || 'G' as total_size , free ...
- ctfhub技能树—web前置技能—http协议—响应包源代码
打开靶机环境 查看网页是一个贪吃蛇小游戏 根据提示查看源码 发现flag 至此HTTP协议结束
- 详解MySQL执行事务的语法和流程
摘要:MySQL 提供了多种存储引擎来支持事务. MySQL 提供了多种存储引擎来支持事务.支持事务的存储引擎有 InnoDB 和 BDB,其中,InnoDB 存储引擎事务主要通过 UNDO 日志和 ...
- go语言循环变量
阅读go语言圣经第五章第六节介绍到了捕获迭代变量 package main import ( "fmt" ) func main() { var lis []func() for ...
- 深入研究.NET 5的开放式遥测
OpenTelemetry 介绍 OpenTelemetry是一种开放的源代码规范,工具和SDK,用于检测,生成,收集和导出遥测数据(指标,日志和跟踪),开放遥测技术得到了Cloud Native C ...
- DSL是什么?Elasticsearch的Query DSL又是什么?
1.DSL简介 DSL 其实是 Domain Specific Language 的缩写,中文翻译为领域特定语言.而与 DSL 相对的就是 GPL,这里的 GPL 并不是我们知道的开源许可证(备注:G ...
- Mybatis Plus 3.4版本之后分页插件的变化
一.MybatisPlusInterceptor 从Mybatis Plus 3.4.0版本开始,不再使用旧版本的PaginationInterceptor ,而是使用MybatisPlusInter ...