-->
当前位置:首页 > 题库

PROGRAMMING:Maximal continuous subsequence

Luz5年前 (2021-05-10)题库458
Given the sequence of K integers {N1, N2,..., NK}, any continuous subsequence can be expressed as {Ni, Ni + 1,..., NJ}, where 1 < = I < = J < = K. For example, given sequence {- 2,11, - 4,13, - 5, - 2}, its maximum continuous subsequence is {11, - 4,13}, and its maximum sum is 20.
###Input format:
The test input includes several test cases, and each test case takes up two lines. The first line gives a positive integer k (< 10000), and the second line gives K integers separated by spaces. When k is 0, the input ends and the use case is not processed.
###Output format:
For each test case, output the maximum sum in line 1. If all k elements are negative, define the maximum sum as 0.
###Input example:
Here is a set of inputs. For example:
```in
six
-2 11 -4 13 -5 -2
ten
-10 1 2 3 4 -5 -23 3 7 -21
six
5 -8 3 2 5 0
one
ten
three
-1 -5 -2
three
-1 0 -2
0
```
###Output example:
The corresponding output is given here. For example:
```out
twenty
ten
ten
ten
0
0
```







answer:If there is no answer, please comment