CF1006C.Three Parts of the Array

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array d1,d2,…,dnd_1, d_2, \dots, d_n 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 sum1sum_1, the sum of elements of the second part be sum2sum_2 and the sum of elements of the third part be sum3sum_3. Among all possible ways to split the array you have to choose a way such that sum1=sum3sum_1 = sum_3 and sum1sum_1 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:

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.

The sum of an empty array is 00.

Your task is to find a way to split the array such that sum1=sum3sum_1 = sum_3 and sum1sum_1 is maximum possible.

给你一个由 nn 个整数组成的数组 d1,d2,…,dnd_1, d_2, \dots, d_n。

你的任务是将该数组划分为三个部分(其中某些部分可以为空),使得数组中的每个元素恰好属于这三个部分中的一个,且每一部分都构成原数组的一个连续子段(可能为空)。

设第一部分所有元素的和为 sum1sum_1,第二部分所有元素的和为 sum2sum_2,第三部分所有元素的和为 sum3sum_3。在所有可能的划分方式中,你需要选择一种满足 sum1=sum3sum_1 = sum_3 且 sum1sum_1 尽可能大的划分方式。

更形式化地,若数组的第一部分包含 aa 个元素,第二部分包含 bb 个元素,第三部分包含 cc 个元素,则:

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.

空数组的和定义为 00。

你的任务是找到一种划分方式,使得 sum1=sum3sum_1 = sum_3 且 sum1sum_1 尽可能大。

输入格式

The first line of the input contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of elements in the array dd.

The second line of the input contains nn integers d1,d2,…,dnd_1, d_2, \dots, d_n (1≤di≤1091 \le d_i \le 10^9) — the elements of the array dd.

输入的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示数组 dd 的元素个数。

输入的第二行包含 nn 个整数 d1,d2,…,dnd_1, d_2, \dots, d_n(1≤di≤1091 \le d_i \le 10^9)—— 表示数组 dd 的元素。

输出格式

Print a single integer — the maximum possible value of sum1sum_1, considering that the condition sum1=sum3sum_1 = sum_3 must be met.

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

输出一个整数——在满足 sum1=sum3sum_1 = sum_3 的前提下,sum1sum_1 的最大可能值。

显然,至少存在一种合法的数组划分方式(例如取 a=c=0a=c=0 且 b=nb=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 sum1sum_1: [1,3,1],[ ],[1,4][1, 3, 1], [~], [1, 4].

In the second example the only way to have sum1=4sum_1=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], [~].

在第一个例子中,唯一一种能最大化 sum1sum_1 的划分方式是:[1,3,1],[ ],[1,4][1, 3, 1], [~], [1, 4]。

在第二个例子中,唯一能使 sum1=4sum_1=4 的划分方式是:[1,3],[2,1],[4][1, 3], [2, 1], [4]。

在第三个例子中,数组只有一种划分方式:[ ],[4,1,2],[ ][~], [4, 1, 2], [~]。

输入解题思路,AI测评打分。不知道怎么写?

首页