Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0

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


Fixed submission:
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N+1):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i + k], dp[i] + abs(h_list[i-1] - h_list[i-1+k]))

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0

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


Fixed submission:
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N+1):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i + k], dp[i] + abs(h_list[i-1] - h_list[i-1+k]))

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k <= N - 1:
            dp[i + k] = min(dp[i + k], dp[i] + abs(h_list[i + k] - h_list[i]))
print(dp[N-1])


Fixed submission:
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N+1):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i + k], dp[i] + abs(h_list[i-1] - h_list[i-1+k]))

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

inf = float("inf")
dp = [inf for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N + 1):
    for k in range(1, K + 1):
        if i + k <= N:
            if dp[i + k] > dp[i] + abs(h_list[i - 1] - h_list[i - 1 + k]):
                dp[i + k] = dp[i] + abs(h_list[i - 1] - h_list[i - 1 + k])

print(dp[N])

Fixed submission:
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N+1):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i + k], dp[i] + abs(h_list[i-1] - h_list[i-1+k]))

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N + 1):
    for k in range(1, K + 1):
        if i + k <= N:
            if dp[i] + abs(h_list[i - 1] - h_list[i - 1 + k]) < dp[i + k]:
                dp[i + k] = dp[i] + abs(h_list[i - 1] - h_list[i - 1 + k])

print(dp[N])


Fixed submission:
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N+1):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i + k], dp[i] + abs(h_list[i-1] - h_list[i-1+k]))

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N+1):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i + k], dp[i] + abs(h_list[i-1] - h_list[i-1+k]))

print(dp[N])


Fixed submission:
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N+1):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i + k], dp[i] + abs(h_list[i-1] - h_list[i-1+k]))

print(dp[N])