import numpy as np

N,K= list(map(int,input().split()))

H = np.array(list(map(int, input().split())))

 

dp = np.zeros(N, dtype=int)

 

for i in range(1,N):

  s=max(i-K,0)

  dp[i]=np.min(dp[s:i]+np.abs(H[s:i]-H[i]))

 

print((dp[-1]))
import sys

n,k = list(map(int, input().split()))



a = list(map(int, input().split()))



dp = [sys.maxsize]*n

dp[0] = 0

for i in range(n):

    for j in range(i+1, i+k+1):

        if j < n:

            dp[j] = min(dp[j], dp[i]+abs(a[i]-a[j]))



print((dp[n-1]))
import numpy as np

N, K = list(map(int, input().split()))
H = np.array(list(map(int, input().split())))
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    s = max(i - K, 0)
    dp[i] = np.min(dp[s:i] + np.abs(H[s:i] - H[i]))
print((dp[-1]))

import sys

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [sys.maxsize] * n
dp[0] = 0
for i in range(n):
    for j in range(i + 1, i + k + 1):
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]))
print((dp[n - 1]))

-import numpy as np +import sys -N, K = list(map(int, input().split())) -H = np.array(list(map(int, input().split()))) -dp = np.zeros(N, dtype=int) -for i in range(1, N): -    s = max(i - K, 0) -    dp[i] = np.min(dp[s:i] + np.abs(H[s:i] - H[i])) -print((dp[-1])) +n, k = list(map(int, input().split())) +a = list(map(int, input().split())) +dp = [sys.maxsize] * n +dp[0] = 0 +for i in range(n): +    for j in range(i + 1, i + k + 1): +        if j < n: +            dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j])) +print((dp[n - 1]))