| Author: | Pavel Mesenev | Time limit: | 2 sec | |
| Input file: | Standard input | Memory limit: | 256 Mb | |
| Output file: | Standard output |
You are given an array of n integers a0, a1, …, an − 1, some of which may be negative. Among all non-empty contiguous blocks al, al + 1, …, ar (with 0 ≤ l ≤ r ≤ n − 1), find the largest possible value of the sum al + al + 1 + … + ar.
If every element is negative, the answer is the single largest element, because the block must be non-empty.
The first line contains one integer n — the length of the array. The second line contains n space-separated integers a0… an − 1.
Print one integer — the maximum sum of a non-empty contiguous block.
1 ≤ n ≤ 2 ⋅ 105
− 109 ≤ ai ≤ 109
The answer fits into a signed 64-bit integer.
| No. | Standard input | Standard output |
|---|---|---|
| 1 |
|
|
| 2 |
|
|
| 3 |
|
|