#P1121. 环状最大两段子段和

    ID: 121 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp线性结构枚举,暴力

环状最大两段子段和

Description

Given a circular sequence aa of length nn (that is, a1a_1 and ana_n are adjacent), choose two contiguous, non-overlapping, and non-empty subarrays whose total sum is maximized.

Input Format

The first line contains an integer nn, the length of the sequence. The second line contains nn integers describing the sequence aa; the ii-th number is aia_i.

Output Format

Output a single integer on one line: the maximum possible sum of two subarrays.

7
2 -4 3 -1 2 -4 3

9

Hint

Constraints

For all test points, it is guaranteed that 2n2×1052 \leq n \leq 2 \times 10^5 and 104ai104-10^4 \leq a_i \leq 10^4.

Translated by ChatGPT 5