D. Array Division
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).

Inserting an element in the same position he was erased from is also considered moving.

Can Vasya divide the array after choosing the right element to move and its new position?

Input

The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.

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

Output

Print YES if Vasya can divide the array after moving one element. Otherwise print NO.

Examples
input
3
1 3 2
output
YES
input
5
1 2 3 4 5
output
NO
input
5
2 2 3 4 5
output
YES
Note

In the first example Vasya can move the second element to the end of the array.

In the second example no move can make the division possible.

In the third example Vasya can move the fourth element by one position to the left.

从一个数列中至多移动一个数字插至任意位置,问是否有可能使得数列可以被分为相等的两部分.

一开始用的map<int,pair<int,int> > 虽然A了可后来发现map的话不能判重会出错的啊,果然被hack了,

用一个map<LL,int> 表示某一个数出现的次数然后模拟即可

#include<bits/stdc++.h>
using namespace std;
#define LL long long
int a[100005];
map<LL,int> M;
int main()
{
int n,i,j,k;
LL sumn=0,ans;
cin>>n;
for(i=1;i<=n;++i){
scanf("%d",a+i);
sumn+=a[i];
++M[a[i]];
}
if(sumn & 1) {
puts("NO");
return 0;
}
LL tmp=sumn/2;
if(M[tmp]>0) {puts("YES");return 0;}
for(i=1;i<=n;++i){
tmp-=a[i];
--M[a[i]];
if(M[tmp]>0) {
puts("YES");
return 0;}
} tmp=sumn/2;
for(i=1;i<=n;++i) ++M[a[i]];
for(i=n;i>=1;i--){
tmp-=a[i];
--M[a[i]];
if(M[tmp]>0) {puts("YES");return 0;}
}
puts("NO");
return 0;
}

CF808D STL的更多相关文章

  1. 详细解说 STL 排序(Sort)

    0 前言: STL,为什么你必须掌握 对于程序员来说,数据结构是必修的一门课.从查找到排序,从链表到二叉树,几乎所有的算法和原理都需要理解,理解不了也要死记硬背下来.幸运的是这些理论都已经比较成熟,算 ...

  2. STL标准模板库(简介)

    标准模板库(STL,Standard Template Library)是C++标准库的重要组成部分,包含了诸多在计算机科学领域里所常见的基本数据结构和基本算法,为广大C++程序员提供了一个可扩展的应 ...

  3. STL的std::find和std::find_if

    std::find是用来查找容器元素算法,但是它只能查找容器元素为基本数据类型,如果想要查找类类型,应该使用find_if. 小例子: #include "stdafx.h" #i ...

  4. STL: unordered_map 自定义键值使用

    使用Windows下 RECT 类型做unordered_map 键值 1. Hash 函数 计算自定义类型的hash值. struct hash_RECT { size_t operator()(c ...

  5. C++ STL简述

    前言 最近要找工作,免不得要有一番笔试,今年好像突然就都流行在线笔试了,真是搞的我一塌糊涂.有的公司呢,不支持Python,Java我也不会,C有些数据结构又有些复杂,所以是时候把STL再看一遍了-不 ...

  6. codevs 1285 二叉查找树STL基本用法

    C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...

  7. STL bind1st bind2nd详解

    STL bind1st bind2nd详解   先不要被吓到,其实这两个配接器很简单.首先,他们都在头文件<functional>中定义.其次,bind就是绑定的意思,而1st就代表fir ...

  8. STL sort 函数实现详解

    作者:fengcc 原创作品 转载请注明出处 前几天阿里电话一面,被问到STL中sort函数的实现.以前没有仔细探究过,听人说是快速排序,于是回答说用快速排序实现的,但听电话另一端面试官的声音,感觉不 ...

  9. STL的使用

    Vector:不定长数组 Vector是C++里的不定长数组,相比传统数组vector主要更灵活,便于节省空间,邻接表的实现等.而且它在STL中时间效率也很高效:几乎与数组不相上下. #include ...

随机推荐

  1. 又一国产855旗舰突然现身:支持5G

    12月28日消息,中国联通官方微博放出了vivo NEX 5G版样机.如图所示,该机搭载骁龙855移动平台及X50 5G调制解调器. 早在8月30日,vivo就宣布完成了面向商用5G智能手机的软硬件开 ...

  2. GDPR给安全的影响

    违反GDPR的代价过于巨大,因而你不得不为那些预料不到的后果考虑,而且因为无法使用Whois数据,无形中也扩大了威胁界面.因为GDPR的存在,可供黑客入侵的威胁界面显著增长,不是增加了一点点,而是翻了 ...

  3. MySQL备份与恢复-innobackupex

    :上一片myloder搞崩溃,为什么百度的博文都是抄袭一模一样的,哎烦! 这一片文章我们来介绍物理备份工具xtracebackup! 首先是安装可以percona官网下载安装,下载rpm包直接yum安 ...

  4. bzoj1651 / P2859 [USACO06FEB]摊位预订Stall Reservations

    P2859 [USACO06FEB]摊位预订Stall Reservations 维护一个按右端点从小到大的优先队列 蓝后把数据按左端点从小到大排序,顺序枚举. 每次把比右端点比枚举线段左端点小的数据 ...

  5. Linux下useradd命令创建的用户不能登录的问题

    Linux下useradd命令创建的用户不能登录的问题  问题: 用useradd命令新创建一个用户tester 密码pwdtest mkdir -p /home/tester(创建文件夹) user ...

  6. Python之CMDB资产管理系统

    最近正好在给公司做CMDB资产管理系统,现在做的也差不多了,现在回头吧思路整理下. CMDB介绍 CMDB --Configuration Management Database 配置管理数据库, C ...

  7. Linux 进程学习笔记

    1.什么是程序?什么是进程?它们有什么区别? 定义: 程序:程序(Program)是一个静态的命令集合,程序一般放在磁盘中,然后通过用户的执行来触发.触发后程序会加载到内存中成为一个个体,就是进程. ...

  8. php在Nginx环境下进行刷新缓存立即输出,实现常驻进程轮询。

    以下面这段代码并不会逐个输出,而是当浏览器筹够一定字节数进行统一输出,结果显而易见,10秒后一次性输出所有内容 for($i=0;$i<10;$i++){ echo $i.'</br> ...

  9. 20145118 《Java程序设计》第6周学习总结

    20145118 <Java程序设计>第6周学习总结 教材学习内容总结 1.数据依靠串流在目的地与来源地之间传输,无论来去如何,只要取得InputStream或OutputStream的实 ...

  10. 高通RFC适配RFFE-添加MIPI设备【转】

    本文转载自:https://blog.csdn.net/u011212816/article/details/80828625 RF driver主要设计到的器件 1.Transceiver 2.RF ...