Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]
hs = [0] + [int(x) for x in input().split()]
dp = [0] * (n+1)
mx = 1 << 50
for i in range(2, n + 1):
    mn = mx
    minIndex = max(1, i - k)
    for j in range(minIndex, i):
        v = dp[j] + abs(hs[i] - hs[j])
        if v < mn:
            mn = v
    dp[i] = mn
print(dp[n])

Fixed submission:
n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, min(k,n)):
	dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[:i], hs[:i])])

if k < n:
	for i in range(k, n):
		dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[i-k:i], hs[i-k:i])])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]
hs = [int(x) for x in input().split()]
dp = [0 for _ in range(n+1)]
mx = 1 << 50
for i in range(2, n + 1):
    mn = mx
    minIndex = max(1, i - k)
    for j in range(minIndex, i):
        v = dp[j] + abs(hs[i-1] - hs[j-1])
        if v < mn:
          mn = v
        mn = min(mn, v)
    dp[i] = mn
print(dp[n])

Fixed submission:
n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, min(k,n)):
	dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[:i], hs[:i])])

if k < n:
	for i in range(k, n):
		dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[i-k:i], hs[i-k:i])])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]
hs = [int(x) for x in input().split()]
dp = [0 for _ in range(n+1)]
for i in range(2, n + 1):
    mn = 10**10
    minIndex = max(1, i - k)
    for j in range(minIndex, i):
        v = dp[j] + abs(hs[i-1] - hs[j-1])
        mn = min(mn, v)
    dp[i] = mn
print(dp[n])


Fixed submission:
n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, min(k,n)):
	dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[:i], hs[:i])])

if k < n:
	for i in range(k, n):
		dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[i-k:i], hs[i-k:i])])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]
hs = [int(x) for x in input().split()]
dp = [0] * (n+1)
for i in range(2, n + 1):
    mn = 10**10
    minIndex = max(1, i - k)
    for j in range(minIndex, i):
        v = dp[j] + abs(hs[i-1] - hs[j-1])
        mn = min(mn, v)
    dp[i] = mn
print(dp[n])


Fixed submission:
n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, min(k,n)):
	dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[:i], hs[:i])])

if k < n:
	for i in range(k, n):
		dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[i-k:i], hs[i-k:i])])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n
inf = 1 << 30

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

if k < n:
	for i in range(k, n):
		smallest = inf
		for j in range(i - k, i):
			smallest = min(smallest, dp[j] + abs(hs[i] - hs[j]))
		dp[i] = smallest

print(dp[n-1])

Fixed submission:
n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, min(k,n)):
	dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[:i], hs[:i])])

if k < n:
	for i in range(k, n):
		dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[i-k:i], hs[i-k:i])])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):


n, k = [int(x) for x in input().split()]

hs = [int(y) for y in input().split()]

dp = [0] * n
inf = 1 << 30

for i in range(1, n):
	smallest = inf
	for j in range(max(0,i-k), i):
		smallest = min(smallest, dp[j] + abs(hs[i] - hs[j]))
	dp[i] = smallest
	
print(dp[n-1])



Fixed submission:
n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, min(k,n)):
	dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[:i], hs[:i])])

if k < n:
	for i in range(k, n):
		dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[i-k:i], hs[i-k:i])])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):


n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, n):
	smallest = 1000*1000*1000
	for j in range(max(0,i-k), i):
		#print("i =", i, ", j =", j)
		smallest = min(smallest, dp[j] + abs(hs[i] - hs[j]))
	dp[i] = smallest
    
print(dp[n-1])



Fixed submission:
n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, min(k,n)):
	dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[:i], hs[:i])])

if k < n:
	for i in range(k, n):
		dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[i-k:i], hs[i-k:i])])

print(dp[-1])