#C4173. Taco Jump: Minimum Energy Cost
Taco Jump: Minimum Energy Cost
Taco Jump: Minimum Energy Cost
You are given a set of levels, where each level has a specified height. A jump from one level to a higher level costs an amount of energy equal to the absolute difference between the heights of the two levels.
The participant starts at level 1 (index 0) and must reach the final level (index n-1). They can jump a maximum of k levels ahead in one leap. The goal is to calculate the minimum total energy cost required to reach the final level.
The energy cost between two levels i and j is defined as:
\( \text{cost}(i,j) = |h_j - h_i| \)
where \( h_i \) is the height of level i.
Input is provided via standard input and output should be printed to standard output.
inputFormat
The first line contains two integers n and k, where n is the number of levels and k is the maximum jump length.
The second line contains n space-separated integers representing the heights of each level.
outputFormat
Output a single integer representing the minimum energy cost required to reach the final level from the first level.
## sample5 3
10 30 40 50 20
30