atcoder#AGC008B. [AGC008B] Contiguous Repainting

[AGC008B] Contiguous Repainting

Score : 400400 points

Problem Statement

There are NN squares aligned in a row. The ii-th square from the left contains an integer aia_i.

Initially, all the squares are white. Snuke will perform the following operation some number of times:

  • Select KK 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

  • 1N1051 \leq N \leq 10^5
  • 1KN1 \leq K \leq N
  • aia_i is an integer.
  • ai109|a_i| \leq 10^9

Input

The input is given from Standard Input in the following format:

NN KK

a1a_1 a2a_2 ...... aNa_N

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