#K56027. Maximum Score with Skipping Levels
Maximum Score with Skipping Levels
Maximum Score with Skipping Levels
You are given n levels, where each level i has an associated score s_i. When you play a level, you gain its score, but then you must skip the next k levels. In other words, if you choose level i, the next level you can play is any level j such that
\(j \ge i + k + 1\).
Your task is to determine the maximum possible total score you can achieve by selecting a subset of levels to play, abiding by the skipping rule.
Note: If no previous level is available (i.e. when the skip constraint prevents you from choosing an earlier level), then you simply take the score of the current level.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains two space‐separated integers n and k, where n is the number of levels and k is the number of levels you must skip after playing a level.
- The second line contains n space‐separated integers representing the scores of the levels: s0, s1, ..., sn-1.
outputFormat
The output is a single integer (printed to stdout) which is the maximum achievable score following the skipping rule.
## sample5 1
10 20 30 40 50
90