#P2642. 最大双子段和

最大双子段和

Description

Given an integer sequence of length nn, select two subarrays (contiguous, non-empty segments of the sequence) such that the total sum of the integers in these two subarrays is maximized, and output that total sum. Each subarray must have a minimum length of 11, and the two subarrays must be separated by at least one element.

Input Format

The first line contains an integer representing nn. The second line contains nn integers representing the sequence.

Output Format

Output a single integer, the maximum total sum of the integers in the two selected subarrays.

5
83 223 -13 1331 -935
1637
3
83 223 -13
70

Hint

Constraints:

  • For 30%30\% of the testdata, n100n \le 100.
  • For 60%60\% of the testdata, n104n \le 10^4.
  • For 100%100\% of the testdata, n106n \le 10^6.
  • All values during the computation are guaranteed to fit within the range of a signed 6464-bit integer.

Translated by ChatGPT 5