| XIII UnB Contest Mirror |
|---|
| Finished |
Adrielly really likes music, and to make her bus rides to and from UnB less boring, she decided to create her own playlist!
To do this, she selected the $$$N$$$ most recent songs she listened to (numbered from $$$1$$$ to $$$N$$$) and assigned a value $$$A_i$$$ to each song $$$i$$$. This value represents how much Adrielly likes that song — if it is negative, it is a song she regrets listening to...
Obviously, Adrielly would like to create a playlist that maximizes the sum of the values of the chosen songs! However, she currently has a song stuck in her head with the chorus: "One Every $$$K$$$! One Every $$$K$$$!...". Therefore, if she chooses song $$$i$$$ to be included in the playlist, she cannot choose any song $$$j$$$ with $$$i \lt j \lt i+K$$$.
Help Adrielly make her trips more enjoyable by determining the maximum possible sum of the values of a playlist, following the "One Every $$$K$$$" restriction!
The first line of input contains two numbers: $$$N$$$ and $$$K$$$ $$$(1 \leq K \leq N \leq 10^5)$$$. It is guaranteed that $$$K \cdot N \leq 10^5$$$.
The second line of input contains the $$$N$$$ values $$$A_i$$$ $$$(-10^9 \leq A_i \leq 10^9)$$$.
Print a single line containing the maximum possible sum of the values of a playlist, following the given restriction.
12 31 4 -5 6 19 20 -1 4 5 -3 0 10
39
3 11 2 3
6
3 1-1 -2 -3
0
4 42 3 0 2
3
In the first example case, the best option for Adrielly is to choose the songs with the values: $$$4$$$, $$$20$$$, $$$5$$$, and $$$10$$$.
In the second example case, Adrielly achieves the maximum sum by choosing all the songs.
In the third example case, it is better for Adrielly not to choose any songs because all of them are bad... So the best sum is achieved with an empty playlist (sum $$$0$$$).
In the fourth example case, Adrielly should choose the song with the value $$$3$$$.
| Name |
|---|


