Given a sequence of $N$ integers, choose a non-empty contiguous subarray whose sum is maximum, and print that maximum sum.
Input
First line $N$ ($1 \le N \le 100$); second line $N$ integers ($-1000 \le A_i \le 1000$).
Output
Print the maximum contiguous-subarray sum.
Example 1
Input
5 1 -2 3 4 -5
Output
7
Example 2
Input
3 -5 -1 -10
Output
-1
Example 3
Input
10 10 -3 5 10 -20 5 8 -10 20 1
Output
26
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.