Skip to content
UPEEC

Maximum Subarray Sum

Medium#arrays#dynamic-programming#kadane· solved by 0 · time limit 2.0 s

Find the largest sum of a non-empty contiguous subarray (Kadane's algorithm does it in one pass).

Input

nn, then nn integers.

Output

The maximum sum.

Constraints

1≤n≤1051 \le n \le 10^5, ∣ai∣≤104|a_i| \le 10^4

Sample 1

Input

9
-2 1 -3 4 -1 2 1 -5 4

Output

6

Sign in or join free to run and submit your solution.