n, k, *h = list(map(int, open(0).read().split()))

h += [0] * 200

dp = [0] + [float("inf")] * 100200

for i in range(1, n):

  dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in range(1, k + 1))

print((dp[n - 1]))
n, k, *h = list(map(int, open(0).read().split()))

dp = [0] * n

for i in range(1, n):

  dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in range(1, min(i, k) + 1))

print((dp[n - 1]))
n, k, *h = list(map(int, open(0).read().split()))
h += [0] * 200
dp = [0] + [float("inf")] * 100200
for i in range(1, n):
    dp[i] = min(dp[i - a] + abs(h[i] - h[i - a]) for a in range(1, k + 1))
print((dp[n - 1]))

n, k, *h = list(map(int, open(0).read().split()))
dp = [0] * n
for i in range(1, n):
    dp[i] = min(dp[i - a] + abs(h[i] - h[i - a]) for a in range(1, min(i, k) + 1))
print((dp[n - 1]))

-h += [0] * 200 -dp = [0] + [float("inf")] * 100200 +dp = [0] * n -    dp[i] = min(dp[i - a] + abs(h[i] - h[i - a]) for a in range(1, k + 1)) +    dp[i] = min(dp[i - a] + abs(h[i] - h[i - a]) for a in range(1, min(i, k) + 1))