Problems > Minimum Subarray Sum

Minimum Subarray Sum

Difficulty: 1300 3000 ms 128 MB

dp

Find the minimum possible sum of a non-empty contiguous subarray.

Input: the first line has N; the second line has N integers.

Output: the minimum subarray sum.

Constraints:

  • 1 ≤ N ≤ 105
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
5
3 -4 2 -3 8
Output 1
-5
Input 2
2
5 6
Output 2
5

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.