2128. Maximum subsequence sum

单点时限: 2.0 sec

内存限制: 256 MB

Let a_1, a_2, …, a_n be a sequence of integers. A contiguous subsequence of this sequence is a subsequence a_i, a_i+1, …, a_j-1, a_j for some i,j such that 1 <= i <= j. You have to write a program which when given a sequence of integers, outputs the maximum possible sum of any contiguous subsequence of the sequence.

输入格式

First line of the input will be n, the number of integers in the subsequence. n can be as large as upto 100,000. This will be followed by n integers. Each integer will appear on a different line, and there will be no blank lines in the input.

输出格式

Output the maximum possible sum as defined above.

样例

Input
10
-1
-2
3
-1
4
2
-6
7
-1
5
Output
13

39 人解决,83 人已尝试。

47 份提交通过,共有 109 份提交。

5.1 EMB 奖励。

创建: 16 年,5 月前.

修改: 7 年,2 月前.

最后提交: 1 年,4 月前.

来源: Codewars 2006

题目标签