Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)
dp = np.full(N, 10**9, dtype=int)

dp[0] = 0
for i in range(N-1):
    X = min(N - 1, i + K)
    H = A[i]
    dp[i+1:i+X+1] = np.minimum(np.abs(H-A[i+1:i+X+1])+dp[i], dp[i+1:i+X+1])

print(dp[N - 1])


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

dp=[100000 for i in range(N)]
dp[0]=0

for i,h_now in enumerate(h):
    if i==0:
        continue
    x=max(0,i-K)
    dp[i]=min([dp_i+abs(h_now-h_i) for dp_i,h_i in zip(dp[x:i],h[x:i])])

print(dp[N-1])

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

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

dp[0] = 0

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

print(dp[N - 1])

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

dp=[100000 for i in range(N)]
dp[0]=0

for i,h_now in enumerate(h):
    if i==0:
        continue
    x=max(0,i-K)
    dp[i]=min([dp_i+abs(h_now-h_i) for dp_i,h_i in zip(dp[x:i],h[x:i])])

print(dp[N-1])

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

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

dp[0] = 0

for i in range(1, N):
    h = A[i]
    dp[i] = min(dp[j]+abs(h-A[j]) for j in range(max(0, i-K), i))

print(dp[N - 1])


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

dp=[100000 for i in range(N)]
dp[0]=0

for i,h_now in enumerate(h):
    if i==0:
        continue
    x=max(0,i-K)
    dp[i]=min([dp_i+abs(h_now-h_i) for dp_i,h_i in zip(dp[x:i],h[x:i])])

print(dp[N-1])

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

inf = 10**9
dp = [inf] * (N+5)

dp[0] = 0

for i in range(1, N):
    h = A[i]
    dp[i] = min(dp[j]+abs(h-A[j]) for j in range(max(0, i-K), i))

print(dp[N - 1])


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

dp=[100000 for i in range(N)]
dp[0]=0

for i,h_now in enumerate(h):
    if i==0:
        continue
    x=max(0,i-K)
    dp[i]=min([dp_i+abs(h_now-h_i) for dp_i,h_i in zip(dp[x:i],h[x:i])])

print(dp[N-1])

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

inf = 10**9
dp = [inf] * (N+5)

dp[0] = 0

for i in range(1, N):
    # 後ろを見ていく
    h = A[i]
    dp[i] = min(dp[i-k]+abs(h-A[i-k]) for k in range(1, min(K, i)+1))

print(dp[N - 1])


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

dp=[100000 for i in range(N)]
dp[0]=0

for i,h_now in enumerate(h):
    if i==0:
        continue
    x=max(0,i-K)
    dp[i]=min([dp_i+abs(h_now-h_i) for dp_i,h_i in zip(dp[x:i],h[x:i])])

print(dp[N-1])

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

inf = 10**9
dp = [inf] * (N+5)

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

print(dp[N-1])


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

dp=[100000 for i in range(N)]
dp[0]=0

for i,h_now in enumerate(h):
    if i==0:
        continue
    x=max(0,i-K)
    dp[i]=min([dp_i+abs(h_now-h_i) for dp_i,h_i in zip(dp[x:i],h[x:i])])

print(dp[N-1])

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

dp=[100000 for i in range(N)]
dp[0]=0

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

print(dp[N-1])

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

dp=[100000 for i in range(N)]
dp[0]=0

for i,h_now in enumerate(h):
    if i==0:
        continue
    x=max(0,i-K)
    dp[i]=min([dp_i+abs(h_now-h_i) for dp_i,h_i in zip(dp[x:i],h[x:i])])

print(dp[N-1])