#P1115. 最大子段和

    ID: 115 远端评测题 1000ms 125MiB 尝试: 3 已通过: 3 难度: 3 上传者: 标签>动态规划,dp递推线性结构分治

最大子段和

Description

Given a sequence aa of length nn, choose a non-empty contiguous subarray whose sum is maximized.

Input Format

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

Output Format

Output one line with a single integer, the answer.

7
2 -4 3 -1 2 -4 3

4

Hint

  • Explanation for Sample 1: Choose the subarray [3,5][3, 5], which is {3,1,2}\{3, -1, 2\}; its sum is 44.
  • Constraints:
    • For 40% of the testdata, it is guaranteed that n2×103n \le 2 \times 10^3.
    • For 100% of the testdata, it is guaranteed that 1n2×1051 \le n \le 2 \times 10^5 and 104ai104-10^4 \le a_i \le 10^4.

Translated by ChatGPT 5