A11937 | Three Parts of the Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ 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 $sum_1$ , the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$ . Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$$$sum_1 = \sum\limits_{1 \le i \le a}d_i, $$ $$ sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i, $$ $$ sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i. $$ </p><p>The sum of an empty array is $0$ .</p><p>Your task is to find a way to split the array such that $sum\_1 = sum\_3$ and $sum\_1$$$ is maximum possible.
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 $sum_1$ , the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$ . Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$$$sum_1 = \sum\limits_{1 \le i \le a}d_i, $$ $$ sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i, $$ $$ sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i. $$ </p><p>The sum of an empty array is $0$ .</p><p>Your task is to find a way to split the array such that $sum\_1 = sum\_3$ and $sum\_1$$$ is maximum possible.
输入格式
The first line of the input contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of elements in the array $d$ .
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ( $1 \le d_i \le 10^9$ ) — the elements of the array $d$ .
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ( $1 \le d_i \le 10^9$ ) — the elements of the array $d$ .
输出格式
Print a single integer — the maximum possible value of $sum_1$ , considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$ ).
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$ ).
输入输出样例
输入 #1
5 1 3 1 1 4
输出 #1
5
输入 #2
5 1 3 2 1 4
输出 #2
4
输入 #3
3 4 1 2
输出 #3
0
In the first example there is only one possible splitting which maximizes $sum_1$ : $[1, 3, 1], [~], [1, 4]$ .
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$ .
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$ .
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$ .
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted