Given an integer array of length , find the maximum subarray sum.
A subarray is defined as a contiguous range in an array, and a subarray sum is defined as the sum of all elements in the contiguous range.
Input Specification
The first line will contain the integer .
The second line will contain integers, .
Output Specification
Output the maximum subarray sum in the array. Note that the subarray may be the entire array. However, the subarray must contain at least one element.
Subtasks
Subtask 1 [10%]
Subtask 2 [30%]
Subtask 2 [60%]
No further constraints.
Sample Input 1
5
1 -3 4 2 2
Sample Output 1
8
Sample Input 2
7
5 2 -4 7 9 -2 1
Sample Output 2
19
Explanation For Sample 2
We can take the subarray (-indexed) for a total sum of .
Comments