Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

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

print(dp[N-1])

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

for i in range(1,N):
    now = h[i]
    dp[i] = min([abs(now-h[j])+dp[j] for j in range(max(i-K,0),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 = [0]*(N)

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

print(dp[N-1])

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

for i in range(1,N):
    now = h[i]
    dp[i] = min([abs(now-h[j])+dp[j] for j in range(max(i-K,0),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 = [float("inf")]*(N)
dp[0] = 0

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

print(dp[N-1])

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

for i in range(1,N):
    now = h[i]
    dp[i] = min([abs(now-h[j])+dp[j] for j in range(max(i-K,0),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 = [float("inf")]*(N)
dp[0] = 0

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

print(dp[N-1])

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

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

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*(N)
dp[0] = 0

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

print(dp[N-1])


Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

for i in range(1,N):
    now = h[i]
    dp[i] = min([abs(now-h[j])+dp[j] for j in range(max(i-K,0),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 = [float("inf")]*(N)
dp[0] = 0

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

print(dp[N-1])


Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

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

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
 
cost = [0]
 
for i in range(1,N):
    c = cost[i-1]+abs(h[i]-h[i-1])
    for j in range(2,min(i,K)+1):
        c = min(c,cost[i-j]+abs(h[i]-h[i-j]))
    cost.append(c)
 
print(cost[N-1])

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

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

print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))

cost = [0]

for i in range(1,N):
    cost.append(1000)
    for j in range(max(i,K)):
        cost[i] = min(cost[i],cost[i-j]+abs(h[i]-h[i-j]))

print(cost[N])

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

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

print(dp[N-1])