Dragon
InterviewTime limit1sMemory limit1024 MB
Pick two disjoint blocks of at most K consecutive heads each in a row of N heads to maximize the total fire power removed.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Prefix sum, Sliding window, Array
- Solved
- No attempts yet
Problem
The legendary Slavic hero Ilya Muromets battles a legendary dragon.
The dragon has heads, numbered from left to right. Like any dragon, it can breathe fire; the fire power of the -th head is .
With a single swing of his sword, Muromets can cut off up to consecutive heads. After a swing, the remaining heads close ranks and again form a single consecutive row.
Right now the dragon is dazed, so Muromets manages to make two swings in a row. Find the maximum total fire power that Muromets can eliminate with these two swings.
Input
The first line contains two space-separated integers: the number of heads and Muromets's maximum reach (, ).
The second line contains space-separated integers , the fire power of each head (, ).
Output
Output a single integer: the maximum total fire power that Muromets can eliminate with the two swings.