Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
	dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
print(dp[-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_arr = list(map(int, input().split()))
dp = [0]*N
 
for i in range(1, N):
	dp[i] = min(abs(h_arr[i]-h_arr[j]) + dp[j] for j in range(max(i-K, 0), i))
print(dp[-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(" "))
h_arr = list(map(int, input().split(" ")))
dp = [0]*N
 
for i in range(1, N):
	dp[i] = min(abs(h_arr[i]-h_arr[j]) + dp[j] for j in range(max(i-K, 0), i))
print(dp[N-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(" "))
h_arr = list(map(int, input().split(" ")))
dp = [0]*N

for i in range(1, N):
	dp[i] = min(abs(h_arr[i]-h_arr[j]) + dp[j] for j in range(max(i-K, 0), i))
print(dp[-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(" "))
h_arr = list(map(int, input().split(" ")))
dp = [0]*N

for i in range(1, N):
	dp[i] = min([abs(h_arr[i]-h_arr[j]) + dp[j] for j in range(max(i-K, 0), i)])
print(dp[-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
inp = list(map(int, input().split(" ")))
N, K = inp[0], inp[1]
h_arr = list(map(int, input().split(" ")))
dp = [0]*N

for i in range(1, N):
	dp[i] = min([abs(h_arr[i]-h_arr[j]) + dp[j] for j in range(max(i-K, 0), i)])
print(dp[-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
inp = list(map(int, input().split(" ")))
N, K = inp[0], inp[1]
h_arr = list(map(int, input().split(" ")))
dp = [0 for _ in range(N)]

for i in range(1, N):
	dp[i] = min([abs(h_arr[i]-h_arr[j]) + dp[j] for j in range(max(i-K, 0), i)])
print(dp[-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
inp = list(map(int, input().split(" ")))
N, K = inp[0], inp[1]
h_arr = list(map(int, input().split(" ")))
dp = [9999999 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h_arr[1]-h_arr[0])

for i in range(2, N):
	dp[i] = min([abs(h_arr[i]-h_arr[i-j]) + dp[i-j] for j in range(1, min(i+1, K+1))])
print(dp[-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
inp = list(map(int, input().split(" ")))
N, K = inp[0], inp[1]
h_arr = list(map(int, input().split(" ")))
dp = [9999999 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h_arr[1]-h_arr[0])

for i in range(2, N):
	min_list = []
	for j in range(1, K+1):
		if i >= j:
			min_list.append(abs(h_arr[i]-h_arr[i-j]) + dp[i-j])
	dp[i] = min(min_list)
		
print(dp[-1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])