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

INF = 10**9
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i + 1, K)):
        if dp[i + 1] > dp[i - k] + abs(H[i + 1] - H[i - k]):
            dp[i + 1] = dp[i - k] + abs(H[i + 1] - H[i - k])

print(dp[N-1])

Fixed submission:
N,K = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]

INF = 10**9
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i + 1, K)):
        if dp[i + 1] > dp[i - k] + abs(H[i + 1] - H[i - k]):
            dp[i + 1] = dp[i - k] + abs(H[i + 1] - H[i - k])


print(dp[N - 1])

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

INF = 10**20
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i + 1, K)):
        if dp[i + 1] > dp[i - k] + abs(H[i + 1] - H[i - k]):
            dp[i + 1] = dp[i - k] + abs(H[i + 1] - H[i - k])

print(dp[N-1])

Fixed submission:
N,K = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]

INF = 10**9
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i + 1, K)):
        if dp[i + 1] > dp[i - k] + abs(H[i + 1] - H[i - k]):
            dp[i + 1] = dp[i - k] + abs(H[i + 1] - H[i - k])


print(dp[N - 1])

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

INF = 10**20
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i+1,K)):
            dp[i + 1] = min(dp[i + 1], dp[i - k] + abs(H[i + 1] - H[i - k]))

print(dp[N-1])

Fixed submission:
N,K = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]

INF = 10**9
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i + 1, K)):
        if dp[i + 1] > dp[i - k] + abs(H[i + 1] - H[i - k]):
            dp[i + 1] = dp[i - k] + abs(H[i + 1] - H[i - k])


print(dp[N - 1])

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

INF = 10**20
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, K):
        if i - k >= 0:
            dp[i + 1] = min(dp[i + 1], dp[i - k] + abs(H[i + 1] - H[i  - k]))
        else:
            break
print(dp[N-1])

Fixed submission:
N,K = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]

INF = 10**9
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i + 1, K)):
        if dp[i + 1] > dp[i - k] + abs(H[i + 1] - H[i - k]):
            dp[i + 1] = dp[i - k] + abs(H[i + 1] - H[i - k])


print(dp[N - 1])

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

INF = 10**20
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, K):
        if i - k >= 0:
            dp[i + 1] = min(dp[i + 1], dp[i - k] + abs(H[i + 1] - H[i  - k]))

print(dp[N-1])

Fixed submission:
N,K = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]

INF = 10**9
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i + 1, K)):
        if dp[i + 1] > dp[i - k] + abs(H[i + 1] - H[i - k]):
            dp[i + 1] = dp[i - k] + abs(H[i + 1] - H[i - k])


print(dp[N - 1])