Submit solution


Points: 7 (partial)
Time limit: 1.5s
Memory limit: 256M

Problem type

There are N stones in a line with the i-th stone having a height of a_i.

There is a toad who is initially on the first stone. He will repeat the following action some number of times to reach the last stone:

  • If the toad is currently on stone i, jump to any one of stone i+1, i+2, ..., i+k. Here, a cost of |a_i - a_j| is incurred, where a_j is the stone the toad lands on.

Find the minimum total cost required for the toad to reach the last stone.

Constraints

For all subtasks,

2 \le N \le 10^5

1 \le a_i, k \le 100

Subtask 1 [50%]

k = 2

Subtask 2 [50%]

No additional constraints.

Input Specification

The first line of input will contain N and K.

The next line will contain N space-separated integers a_i.

Output Specification

Output one integer, the minimum total cost required for the toad to reach the last stone.

Sample Input

6 2
1 5 4 5 2 5

Sample Output

4

Explanation for Sample Output

The toad can jump from stone 1 to stone 2, then to stone 4 and finally to stone 6.


Comments

There are no comments at the moment.