C. Three Parts of the Array

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array d1,d2,…,dnd1,d2,…,dn consisting of nn integer numbers.

Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.

Let the sum of elements of the first part be sum1sum1, the sum of elements of the second part be sum2sum2 and the sum of elements of the third part be sum3sum3. Among all possible ways to split the array you have to choose a way such that sum1=sum3sum1=sum3 and sum1sum1 is maximum possible.

More formally, if the first part of the array contains aa elements, the second part of the array contains bb elements and the third part contains ccelements, then:

sum1=∑1≤i≤adi,sum1=∑1≤i≤adi,sum2=∑a+1≤i≤a+bdi,sum2=∑a+1≤i≤a+bdi,sum3=∑a+b+1≤i≤a+b+cdi.sum3=∑a+b+1≤i≤a+b+cdi.

The sum of an empty array is 00.

Your task is to find a way to split the array such that sum1=sum3sum1=sum3 and sum1sum1 is maximum possible.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in the array dd.

The second line of the input contains nn integers d1,d2,…,dnd1,d2,…,dn (1≤di≤1091≤di≤109) — the elements of the array dd.

Output

Print a single integer — the maximum possible value of sum1sum1, considering that the condition sum1=sum3sum1=sum3 must be met.

Obviously, at least one valid way to split the array exists (use a=c=0a=c=0 and b=nb=n).

Examples

input

5
1 3 1 1 4

output

5

input

Copy

5
1 3 2 1 4

output

Copy

4

input

Copy

3
4 1 2

output

Copy

0

Note

In the first example there is only one possible splitting which maximizes sum1sum1: [1,3,1],[ ],[1,4][1,3,1],[ ],[1,4].

In the second example the only way to have sum1=4sum1=4 is: [1,3],[2,1],[4][1,3],[2,1],[4].

In the third example there is only one way to split the array: [ ],[4,1,2],[ ][ ],[4,1,2],[ ].

题解:将给的一组数分成3组(每一组都可以为0个数的和),是的sum1==sum3;  我们可以双向遍历数组,记录和,然后二分查找最大的即可;

AC代码为:

CodeForces1006C-Three Parts of the Array的更多相关文章

  1. [codeForce-1006C]-Three Parts of the Array (简单题)

    You are given an array d1,d2,…,dnd1,d2,…,dn consisting of nn integer numbers. Your task is to split ...

  2. CF 1006C Three Parts of the Array【双指针/前缀和/后缀和/二分】

    You are given an array d1,d2,-,dn consisting of n integer numbers. Your task is to split this array ...

  3. CF1006C 【Three Parts of the Array】

    二分查找水题 记$sum[i]$为$d[i]$的前缀和数组 枚举第一段区间的结尾$i$ 然后二分出$lower$_$bound(sum[n]-sum[i])$的位置$x$,如果$sum[x]$与$su ...

  4. Codeforces 1006C:Three Parts of the Array(前缀和+map)

    题目链接:http://codeforces.com/problemset/problem/1006/C (CSDN又改版了,复制粘贴来过来的题目没有排版了,好难看,以后就截图+题目链接了) 题目截图 ...

  5. codeforces 442C C. Artem and Array(贪心)

    题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. cf442C Artem and Array

    C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. wp8 入门到精通 测量代码执行时间

    Stopwatch time = new Stopwatch(); byte[] target = new byte[size]; for (int j = 0; j < size; j++) ...

  8. split(),preg_split()与explode()函数分析与介

    split(),preg_split()与explode()函数分析与介 发布时间:2013-06-01 18:32:45   来源:尔玉毕业设计   评论:0 点击:965 split()函数可以实 ...

  9. Blitz Templates介绍

    Blitz Templates Blitz Templates-应用于大型互联网项目的非常强大非常快的模板引擎.   下载: sourceforge, 源代码 主页, win32 二进制文件, 其他语 ...

随机推荐

  1. SpringMVC错误:nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.clas

    这是jar包冲突引起的 spring-core.jar已经有asm 所以不用再单独导入asm包了

  2. 点击a标签的时候出现虚影

    在a标签中添加 outline:none;就可以去除了

  3. saprk性能调优参考

    1.Tuning Spark 文档 原文:http://spark.apache.org/docs/latest/tuning.html 翻译参考:https://www.cnblogs.com/lh ...

  4. ubuntu18 拨号连接宽带网络方法

    1.打开终端查看以太网网卡编号 2.打开/usr/share/applications/ 3.点击network connections 4.点击左下角的+号 5.连接类型选择DSL/PPPoE 6. ...

  5. web自动化测试启示篇

    1.首先,对于想学自动化测试的朋友,那么你得懂一种语言,常用的比如Java或者Python.因为没有语言基础,你是写不出自动化脚本的. 我个人选择java 2.有了开发语言的铺垫,那么开始入手Sele ...

  6. 记一次YUV图像分析(二)

    当你有一帧图像的原始(Raw)数据,不知道是RGB像素图还YUV格式时,可以利用YUV的灰度图成块状能量的特点(这也是为什么YUV格式可以被压缩编码的原因),进行简单的分辨. 当你用hexdump一类 ...

  7. MachO文件详解--逆向开发

    今天是逆向开发的第5天内容--MachO文件(Mac 和 iOS 平台可执行的文件),在逆向开发中是比较重要的,下面我们着重讲解一下MachO文件的基本内容和使用. 一.MachO概述 1. 概述 M ...

  8. Python第五天 列表练习 元组类型 字典类型 小购物车练习

    # 反转 reverse# l=['lili','asdf','qwer','80000']# l.reverse()# print(l) # ['80000', 'qwer', 'asdf', 'l ...

  9. python_09

    今日内容: scrapy各组件 Components: 1.引擎(EGINE) 引擎负责控制系统所有组件之间的数据流,并在某些动作发生时触发事件.有关详细信息,请参见上面的数据流部分. 2.调度器(S ...

  10. Alibaba Nacos 学习(三):Spring Cloud Nacos Discovery - FeignClient,Nacos 服务注册与发现

    Alibaba Nacos 学习(一):Nacos介绍与安装 Alibaba Nacos 学习(二):Spring Cloud Nacos Config Alibaba Nacos 学习(三):Spr ...