Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
h = list(map(int, input().split()))
 
dp = [0] * N
for i in range(0, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = min(tmp)
 
print(dp[-1])

Fixed submission:
N,K = map(int, input().split())
h = list(map(int, input().split()))
 
dp = [0] * N
for i in range(1, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = min(tmp)
 
print(dp[-1])

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(0, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
        dp[i] = min(tmp)
 
print(dp[-1])

Fixed submission:
N,K = map(int, input().split())
h = list(map(int, input().split()))
 
dp = [0] * N
for i in range(1, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = min(tmp)
 
print(dp[-1])

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

Fixed submission:
N,K = map(int, input().split())
h = list(map(int, input().split()))
 
dp = [0] * N
for i in range(1, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = min(tmp)
 
print(dp[-1])

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

Fixed submission:
N,K = map(int, input().split())
h = list(map(int, input().split()))
 
dp = [0] * N
for i in range(1, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = min(tmp)
 
print(dp[-1])

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(0, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    for j in range(1, bef + 1):
        tmp = (dp[i - j] + abs(h[i] - h[i - j]))
        if tmp < dp[i] or dp[i] == 0:
            dp[i] = tmp

print(dp[-1])

Fixed submission:
N,K = map(int, input().split())
h = list(map(int, input().split()))
 
dp = [0] * N
for i in range(1, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = min(tmp)
 
print(dp[-1])