Item 2
Time limit2sMemory limit1024 MB
Find the maximum sum of picked values when each interior picked run must span at least K positions, while runs touching either end of the line are exempt.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Prefix sum, Array
- Solved
- No attempts yet
Problem
An infinitely long vertical line extends to the left and right, and items are placed on it. The -th item is at position and has value .
Juwon has tongs of length . Juwon chooses an integer coordinate (), and the tongs pick up every item in the range from to . A picked item disappears from its position and cannot be put back. Juwon uses the tongs as many times as needed to make the total value of the picked items as large as possible.
Find the maximum total value Juwon can pick up. Juwon may never use the tongs, in which case the total value is 0.
Input
The first line contains the number of items and the tong length .
The second line contains the item values in order, separated by spaces.
Output
Print the maximum total value of the picked items.
Constraints
- All input numbers are integers.
Hint
The answer can exceed the 32-bit integer range, so C/C++ users should use the long long type, and Java users should use the long type.