Buggy python submission (verdict: Time Limit Exceeded):
# （高速化）貰うDP
# mainで囲まないと間に合わない
def main():
    N,K=map(int,input().split())
    H=list(map(int,input().split()))
    INF=10**9
    add_list=[INF]*K

    H.extend(add_list)

    dp=[INF]*(N+100) #Kの分追加
    dp[0]=0
    for n in range(N):
        for k in range(n+1,n+K+1):
            dp[k]=min(dp[k], dp[n]+abs(H[n]-H[k]))
    print(dp[N-1])

if __name__ == '__main__':
    main()

Fixed submission:
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# （高速化）貰うDP
N,K=map(int,input().split())
h=[int(_) for _ in input().split()]

dp=[0]*(N)

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Fixed submission:
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# 貰うDP
N,K=map(int,input().split())
h=[int(_) for _ in input().split()]

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

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Fixed submission:
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Fixed submission:
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# 配るDP
N,K=map(int,input().split())
H=list(map(int,input().split()))
INF=10**9
add_list=[INF]*K

H.extend(add_list)

dp=[INF]*(N+100) #Kの分追加
dp[0]=0
for n in range(N):
    for k in range(n+1,n+K+1):
        dp[k]=min(dp[k], dp[n]+abs(H[n]-H[k]))
print(dp[N-1])

Fixed submission:
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=list(map(int,input().split()))
INF=10**9
add_list=[INF]*K

H.extend(add_list)
K_LOOP=K+1

dp=[INF]*(N+100) #Kの分追加
dp[0]=0
for n in range(N):
    for k in range(1,K_LOOP):
        dp[n+k]=min(dp[n+k], dp[n]+abs(H[n]-H[n+k]))
print(dp[N-1])

Fixed submission:
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=list(map(int,input().split()))
INF=10**9
add_list=[INF]*K

H.extend(add_list)

dp=[INF]*(N+100) #Kの分追加
dp[0]=0
for n in range(N):
    for k in range(1,K+1):
        dp[n+k]=min(dp[n+k], dp[n]+abs(H[n]-H[n+k]))
print(dp[N-1])

Fixed submission:
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])