Problems > Maximum Circular Subarray

Maximum Circular Subarray

Difficulty: 1700 3000 ms 128 MB

dp

The array is circular: a subarray may wrap from the end to the start. Find the maximum non-empty subarray sum.

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

Output: the maximum circular subarray sum.

Constraints:

  • 1 ≤ N ≤ 105
  • −104 ≤ ai ≤ 104

Sample Tests

Input 1
5
5 -3 5 1 -2
Output 1
9
Input 2
3
-3 -2 -1
Output 2
-1

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.