Buggy python submission (verdict: Time Limit Exceeded):
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):

    stepLim = min(K,i)
    temp = 9999999999999999999
    for j in range(1,stepLim + 1):
        ind = i-j
        c = dp[ind]+abs(hs[i]-hs[ind])
        if temp >c:
                temp = c
    dp[i] = temp
print(dp[-1])

Fixed submission:
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
#ind → i-1 ~ i-stepLim -1   [i-stepLim -1:i]
    stepLim = min(K,i)
    temp = 9999999999999999999
    dp[i] = min([d+abs(hs[i]-h) for d,h in zip(dp[i-stepLim:i],hs[i-stepLim:i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [0] 
 

for i in range(1,N):
 
    stepLim = min(K,i)
    temp = 9999999999999999999
    for j in range(1,stepLim + 1):
        c = dp[i-j]+abs(hs[i]-hs[i-j])
        if temp >c:
                temp = c
    dp.append(temp)
print(dp[-1])

Fixed submission:
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
#ind → i-1 ~ i-stepLim -1   [i-stepLim -1:i]
    stepLim = min(K,i)
    temp = 9999999999999999999
    dp[i] = min([d+abs(hs[i]-h) for d,h in zip(dp[i-stepLim:i],hs[i-stepLim:i])])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [] 

dp[0] = 0
for i in range(1,N):

    stepLim = min(K,i)
    temp = 9999999999999999999
    for j in range(1,stepLim + 1):
        c = dp[i-j]+abs(hs[i]-hs[i-j])
        if temp >c:
                temp = c
    dp.append(temp)
print(dp[-1])

Fixed submission:
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
#ind → i-1 ~ i-stepLim -1   [i-stepLim -1:i]
    stepLim = min(K,i)
    temp = 9999999999999999999
    dp[i] = min([d+abs(hs[i]-h) for d,h in zip(dp[i-stepLim:i],hs[i-stepLim:i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):

    stepLim = min(K,i)
    temp = 9999999999999999999
    for j in range(1,stepLim + 1):
        c = dp[i-j]+abs(hs[i]-hs[i-j])
        if temp >c:
                temp = c
    dp[i] = temp
print(dp[-1])

Fixed submission:
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
#ind → i-1 ~ i-stepLim -1   [i-stepLim -1:i]
    stepLim = min(K,i)
    temp = 9999999999999999999
    dp[i] = min([d+abs(hs[i]-h) for d,h in zip(dp[i-stepLim:i],hs[i-stepLim:i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
    temp = []
    stepLim = min(K,i)
#     stepLim = min(K,i)  #stepLim→上限

    for j in range(1,stepLim + 1):
        c = dp[i-j]+abs(hs[i]-hs[i-j])
        temp.append(c)
    dp[i] = min(temp)
print(dp[-1])

Fixed submission:
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
#ind → i-1 ~ i-stepLim -1   [i-stepLim -1:i]
    stepLim = min(K,i)
    temp = 9999999999999999999
    dp[i] = min([d+abs(hs[i]-h) for d,h in zip(dp[i-stepLim:i],hs[i-stepLim:i])])
print(dp[-1])