#t90. 最大连续子列和问题

最大连续子列和问题

Maximum Continuous Subsequence Sum

Problem Description

Given a sequence of KK integers N1,N2,…,NKN_1, N_2, \dots, N_K, a "continuous subsequence" is defined as Ni,Ni+1,…,NjN_i, N_{i+1}, \dots, N_j, where 1≤i≤j≤K1 \le i \le j \le K. The "maximum continuous subsequence sum" is the largest among the sums of all such continuous subsequences. For example, given the sequence −2,11,−4,13,−5,−2-2, 11, -4, 13, -5, -2, the continuous subsequence 11,−4,1311, -4, 13 has the maximum sum, which is 2020.

Write a program to compute the maximum continuous subsequence sum of a given integer sequence.

Input Format

The first line gives a positive integer K (≤105)K\ (\le 10^5).

The second line gives the KK integers, separated by spaces.

Output Format

Output the maximum continuous subsequence sum on a single line (guaranteed to fit within the range of int).

If all integers in the sequence are negative, output 00.

Sample Input

6
-2 11 -4 13 -5 -2

Sample Output

20