LearnPy Hub
← Arena
AdvancedRating 1900

Best Sum With Limited Gaps

Choose a non-empty subsequence so that every two chosen neighbours are at most k positions apart. Print the largest possible sum.

Input

n and k, then n integers.

Output

One integer.

Sample 1

Input
5 2
10 2 -10 5 20
Output
37

Sample 2

Input
3 1
-1 -2 -3
Output
-1
solution.py
Output appears here
Best Sum With Limited Gaps · Python Arena problem · LearnPy Hub