Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int,input().split()))
dp = [0]*n
a = list(map(int, input().split()))

for i in range(1, n):
  dp[i] =  min([dp[i-j-1]+abs(a[i]-a[i-j-1]) for j in range(min(k, i))])
print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = np.array([10**5]*n)
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = np.min(np.array([dp[i-j]+abs(h[i]-h[i-j]) 
                        for j in range(1, min(k, i)+1)]))

print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1))
#    for j in range(1, min(k, i)+1):  
#        dp[i] = min([dp[i], dp[i-j]+abs(h[i]-h[i-j])])
        #print(i, dp[i])

print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    #dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])
    for j in range(1, min(k, i)+1):  
        dp[i] = min([dp[i], dp[i-j]+abs(h[i]-h[i-j])])
        #print(i, dp[i])

print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

dp = np.zeros(n, dtype=int)
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):

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

dp = [0]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [0]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n):
    cands = [dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)]
    dp[i] = min(cands)

print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n):
    cands = [dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)]
    dp[i] = min(cands)

print(dp[n-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2, n): 
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(k, i)+1)])

print(dp[n-1])