博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #498 (Div. 3)
阅读量:5339 次
发布时间:2019-06-15

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

 

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 cc elements, then:

sum1=1iadi,sum1=∑1≤i≤adi, sum2=a+1ia+bdi,sum2=∑a+1≤i≤a+bdi, sum3=a+b+1ia+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 (1n21051≤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 (1di1091≤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
Copy
5 1 3 1 1 4
Output
Copy
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],[ ] .

题意:将长度为n的集合划分为3个集合要求sum1==sum3,并且求出在满足条件的基础上sum1的最大值,sum1,sum2均可为空集。

分析:我们可以sum1从前往后加,sum3从后往前加,从满足条件(sum1==sum3)中取最大值就OK。

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 typedef long long ll; 9 using namespace std;10 const int MAXN=1e6+10;11 int str[MAXN];12 int m,n;13 int main()14 {15 cin>>m;16 for(int i=0;i
>str[i];19 }20 int l=1,r=m-2;21 ll kk=0;22 ll ans1=str[0],ans2=str[m-1];23 while(l<=r)24 {25 if(ans1
l)//在此一定判断一下是否越界,我死在这一次39 ans2+=str[r--];40 }41 }42 if(ans1==ans2&&m>1)//当m<2时不满足条件,ans=043 kk=max(ans1,kk);44 cout<
<

 

转载于:https://www.cnblogs.com/moomcake/p/9417474.html

你可能感兴趣的文章
XML中CDATA和#PCDATA的区别
查看>>
6)添加一个窗口的图标
查看>>
SQL SERVER的锁机制(二)——概述(锁的兼容性与可以锁定的资源)
查看>>
POJ - 1422 Air Raid 二分图最大匹配
查看>>
Road Map
查看>>
正则替换中的一个Bug
查看>>
HI3531uboot开机画面 分类: arm-linux-Ubunt...
查看>>
制作U盘启动CDLinux 分类: 生活百科 ...
查看>>
leetcode——Best Time to Buy and Sell Stock
查看>>
Android LinearLayout 的几个属性
查看>>
strcpy函数里的小九九
查看>>
搭建ssm过程中遇到的问题集
查看>>
OpenLayers绘制图形
查看>>
tp5集合h5 wap和公众号支付
查看>>
Flutter学习笔记(一)
查看>>
iOS10 国行iPhone联网权限问题处理
查看>>
洛谷 P1991 无线通讯网
查看>>
[HIHO1184]连通性二·边的双连通分量(双连通分量)
查看>>
Codeforces Round #178 (Div. 2) B. Shaass and Bookshelf 【动态规划】0-1背包
查看>>
SparkStreaming 源码分析
查看>>