6702.Maximum Subarray Sum

Time Limit: 1s Memory Limit: 512MB

Given an array of $n$ integers, your task is to find the maximum sum of values in a contiguous, nonempty subarray.

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the size of the array.

The second line has $n$ integers $x_1,x_2,\dots,x_n$ : the array values.

  • $1 \le n \le 2 \cdot 10^5$
  • $-10^9 \le x_i \le 10^9$

Output Format(To the terminal/stdout)

Print one integer: the maximum subarray sum.

Sample Input

Copy
8
-1 3 -2 5 3 -5 2 2
 \n
  · ·  · · ·  · · \n

Sample Output

Copy
9
 \n
Source: CSES, Sorting and Searching, 1643

Submit

请先 登录

© 2025 FAQs