atcoder#AGC008B. [AGC008B] Contiguous Repainting
[AGC008B] Contiguous Repainting
Score : points
Problem Statement
There are squares aligned in a row. The -th square from the left contains an integer .
Initially, all the squares are white. Snuke will perform the following operation some number of times:
- Select consecutive squares. Then, paint all of them white, or paint all of them black. Here, the colors of the squares are overwritten.
After Snuke finishes performing the operation, the score will be calculated as the sum of the integers contained in the black squares. Find the maximum possible score.
Constraints
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the maximum possible score.
5 3
-10 10 -10 10 -10
10
Paint the following squares black: the second, third and fourth squares from the left.
4 2
10 -10 -10 10
20
One possible way to obtain the maximum score is as follows:
- Paint the following squares black: the first and second squares from the left.
- Paint the following squares black: the third and fourth squares from the left.
- Paint the following squares white: the second and third squares from the left.
1 1
-10
0
10 5
5 -4 -5 -8 -4 7 2 -4 0 7
17