博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 21 D.Array Division(二分)
阅读量:7048 次
发布时间:2019-06-28

本文共 1778 字,大约阅读时间需要 5 分钟。

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.

题目链接:http://codeforces.com/contest/808/problem/D

题意:在数组中移动一个数 使得分组可以分割成两个数组 使得两个数组之和相等

分析:

首先分两种情况

1. 往后面移动一个数到前面  (维护前缀和 看看后面有没有符合条件的数)
2. 移掉一个数            (移掉第i个数 看看连续的数能不能符合条件) 

用二分做,观摩观摩

1 #include 
2 using namespace std; 3 typedef long long ll; 4 const int N=100010; 5 ll s[N],a[N],sum; 6 int n; 7 bool find(int l,int r,ll x) 8 { 9 while(l<=r)10 {11 int mid=(l+r)/2;12 if(s[mid]==x)13 return 1;14 if(s[mid]

 

转载地址:http://aqcol.baihongyu.com/

你可能感兴趣的文章
ListView控件的基本操作
查看>>
jQuery 参考手册 - 属性操作
查看>>
C–gcc命令行下的参数
查看>>
oracle之表管理
查看>>
mysql 连接查询 和 子查询
查看>>
给开发维护大型项目开发者的建议
查看>>
能过修改注册表来修改IE的设置
查看>>
memcache/memcached/memcachedb 配置、安装(转)
查看>>
JQuery Tree插件——zTree v3.2 正式版发布
查看>>
工作的思考二:无效的沟通
查看>>
【OpenStack】OpenStack系列12之OpenStack自动化测试详解
查看>>
js的初始化
查看>>
如何让图片在垂直方向与 div的底部对齐 水平居中
查看>>
JAVAssist---动态改动注解
查看>>
swift:自定义UICollectionViewFlowLayout
查看>>
UploadFile控件,提交图片后,页面预览显示刚刚提交的图片
查看>>
调查:2013年十大急需的热门IT人才
查看>>
Axure例——幻灯片切换
查看>>
为什么memset的第二个参数不把int替换成char
查看>>
超级芯片电路板问世 比现有电脑快9000倍
查看>>