CodeForces1006C-Three Parts of the Array
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的更多相关文章
- [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 ...
- 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 ...
- CF1006C 【Three Parts of the Array】
二分查找水题 记$sum[i]$为$d[i]$的前缀和数组 枚举第一段区间的结尾$i$ 然后二分出$lower$_$bound(sum[n]-sum[i])$的位置$x$,如果$sum[x]$与$su ...
- Codeforces 1006C:Three Parts of the Array(前缀和+map)
题目链接:http://codeforces.com/problemset/problem/1006/C (CSDN又改版了,复制粘贴来过来的题目没有排版了,好难看,以后就截图+题目链接了) 题目截图 ...
- codeforces 442C C. Artem and Array(贪心)
题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- cf442C Artem and Array
C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- wp8 入门到精通 测量代码执行时间
Stopwatch time = new Stopwatch(); byte[] target = new byte[size]; for (int j = 0; j < size; j++) ...
- split(),preg_split()与explode()函数分析与介
split(),preg_split()与explode()函数分析与介 发布时间:2013-06-01 18:32:45 来源:尔玉毕业设计 评论:0 点击:965 split()函数可以实 ...
- Blitz Templates介绍
Blitz Templates Blitz Templates-应用于大型互联网项目的非常强大非常快的模板引擎. 下载: sourceforge, 源代码 主页, win32 二进制文件, 其他语 ...
随机推荐
- linux引导之grub2
先了解下什么是Bootloader 以下是百度百科释意 在嵌入式操作系统中,BootLoader是在操作系统内核运行之前运行.可以初始化硬件设备.建立内存空间映射图,从而将系统的软硬件环境带到一个合适 ...
- Spring资源下载(官网)
Spring 资源jar包官网下载地址: 点击Spring
- PHP经典算法题
1.百钱买百鸡 公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,用100文钱买一百只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱. 分析:估计现在小学生都能手工推 ...
- secureCRT连接虚拟机
1.secureCRT英文版下载 链接:https://pan.baidu.com/s/1LFWD-k2r4ZB7DHQA66QogQ 密码:khmo 破解方式参考 2.虚拟机静态IP设置 参考 3. ...
- 一分钟带你了解下MyBatis的动态SQL!
MyBatis的强大特性之一便是它的动态SQL,以前拼接的时候需要注意的空格.列表最后的逗号等,现在都可以不用手动处理了,MyBatis采用功能强大的基于OGNL的表达式来实现,下面主要介绍下. 一. ...
- poj 3974 Palindrome (manacher)
Palindrome Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 12616 Accepted: 4769 Desc ...
- linux与Windows进程控制
进程管理控制 这里实现的是一个自定义timer用于统计子进程运行的时间.使用方式主要是 timer [-t seconds] command arguments 例如要统计ls的运行时间可以直接输入t ...
- python:正则1
鱼c(扩展阅读): Python3 如何优雅地使用正则表达式(详解一) Python3 如何优雅地使用正则表达式(详解二) Python3 如何优雅地使用正则表达式(详解三) Python3 如何优雅 ...
- C. Present(二分 + 扫描线)
题目链接:http://codeforces.com/contest/460/problem/C 题意: n盆花,浇k次水, 每次可使花高度 + 1, 每次可浇相邻的w盆,ai 表示 i-th盆花 的 ...
- java中的transient关键字详解
目录 1.何谓序列化? 2.为何要序列化? 3.序列化与transient的使用 4.java类中serialVersionUID作用 5.transient关键字小结 前言 说实话学了一段时间jav ...