#P2627. [USACO11OPEN] Mowing the Lawn G

[USACO11OPEN] Mowing the Lawn G

Description

After winning the town’s Best Lawn contest a year ago, Farmer John became lazy and hasn’t mowed the lawn since. Now, a new Best Lawn contest is starting, and Farmer John hopes to win again.

However, Farmer John’s lawn is a mess, so he can only rely on his cows to do the job. Farmer John has NN (1N1051\le N\le 10^5) cows in a row, numbered 1N1\ldots N. Each cow has a different efficiency; cow ii has efficiency EiE_i (0Ei1090\le E_i\le 10^9).

Neighboring cows are very familiar with each other, so if Farmer John schedules more than KK (1KN1\le K\le N) consecutive cows, they will go on strike to throw a party :). Therefore, Farmer John needs your help to compute the maximum total efficiency he can obtain, with no stretch of more than KK consecutive cows.

Input Format

The first line contains two integers NN and KK separated by a space.

The second to (N+1)(N+1)-th lines: the (i+1)(i+1)-th line contains an integer EiE_i.

Output Format

Output a single value: the maximum total efficiency that Farmer John can obtain.

5 2
1
2
3
4
5

12

Hint

Translated by ChatGPT 5