Buggy python submission (verdict: Runtime Error):
INF = 10**9

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

dp = [INF] * (n + 10000 * k)
dp[0] = 0

for i in range(1, n):
    a = INF
    hsi = hs[i]
    for m in range(1, k + 1):
        j = i - m
        v = dp[j] + abs(hs[j] - hsi)
        if a > v:
            a = v
    dp[i] = a
print(dp[n - 1])


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

hs = list(map(int, input().split(' ')))

dp = [float('inf')] * (n + k + 1)
dp[0] = 0

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

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9

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

dp = [INF] * n
dp[0] = 0

for i in range(1, n):
    l = i if i < k else k
    a = INF
    hsi = hs[i]
    for m in range(1, l + 1):
        j = i - m
        v = dp[j] + abs(hs[j] - hsi)
        if a > v:
            a = v
    dp[i] = a
print(dp[-1])


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

hs = list(map(int, input().split(' ')))

dp = [float('inf')] * (n + k + 1)
dp[0] = 0

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

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9

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

dp = [INF] * n
dp[0] = 0

for i in range(1, n):
    l = i if i < k else k
    a = INF
    hsi = hs[i]
    for m in range(1, l + 1):
        v = dp[i - m] + abs(hs[i - m] - hsi)
        if a > v:
            a = v
    dp[i] = a
print(dp[-1])


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

hs = list(map(int, input().split(' ')))

dp = [float('inf')] * (n + k + 1)
dp[0] = 0

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

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9

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

dp = [INF] * n
dp[0] = 0

for i in range(1, n):
    l = min([i, k])
    a = INF
    hsi = hs[i]
    for m in range(1, l + 1):
        v = dp[i - m] + abs(hs[i - m] - hsi)
        if a > v:
            a = v
    dp[i] = a
print(dp[-1])


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

hs = list(map(int, input().split(' ')))

dp = [float('inf')] * (n + k + 1)
dp[0] = 0

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

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9

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

dp = [INF] * n
dp[0] = 0

for i in range(1, n):
    l = min([i, k])
    for m in range(1, l + 1):
        v = dp[i - m] + abs(hs[i - m] - hs[i])
        if dp[i] > v:
            dp[i] = v

print(dp[-1])


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

hs = list(map(int, input().split(' ')))

dp = [float('inf')] * (n + k + 1)
dp[0] = 0

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

print(dp[n - 1])