Akuna CapitalOA #2
Disjoint Subarrays Max Sum
Estimated MediumJudge-ready
Topics (AI-labelled)DP BasicsPrefix & Ranges
You must cut the array at some adjacent position into a non-empty left part and a non-empty right part, both contiguous. Find the maximum non-empty contiguous subarray sum of the left part and of the right part separately, then add the two; return the maximum over all cuts. The cut point and the maximum subarrays within the two parts may vary independently.
Input
The first line contains n; the second line contains n integers a[i]. This site adds 2≤n≤200000 and −1000000000≤a[i]≤1000000000, so that both parts are non-empty and the sums are safe in 64 bits.
Output
Output one integer, the best sum over all valid cuts.
Example 1
Input:
6
-1 4 -2 5 -3 6
Output:
13
Example 2
Input:
2
-5 -2
Output:
-7
Example 3
Input:
3
2 -10 3
Output:
5
Editorial
Loading solution…