Buggy python submission (verdict: Time Limit Exceeded):
import sys

n ,k = map(int, input().split())
arr = list(map(int, input().split()))

dp = [sys.maxsize] * n
dp[0] = 0

for i in range(0,n):
    for j in range(i+1, min(i+k+1,n)):
        dp[j] = min(dp[i] + abs(arr[j]-arr[i]),dp[j])

print(dp[-1])

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
 
	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
def f():
    n,k = map(int,input().split())

    h = list(map(int,input().split()))

#print(h)

    o = [0]* n

    for a in range(1,n):
        o[a] = min(o[b]+abs(h[a]-h[b]) for b in range(max(0,a-k),a))

    print(o[n-1])

f()

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
 
	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()

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

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
 
	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()

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

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
 
	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())

h = list(map(int,input().split()))

#print(h)

o = [0]* n

for a in range(1,n):
    o[a] = min(o[b]+abs(h[a]-h[b]) for b in range(max(0,a-k),a))

print(o[n-1])

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
 
	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())

h = list(map(int,input().split()))

#print(h)

o = [0]* n

for a in range(1,n):
    o[a] = min(o[b]+abs(h[a]-h[b]) for b in range(max(0,a-k),a))

print(o[-1])


Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
 
	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())

h = list(map(int,input().split()))

#print(h)

o = [0]* n

for a in range(1,n):
    o[a] = min(o[b]+abs(h[a]-h[b]) for b in range(max(0,a-k),a))

print(o[-1])





Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
 
	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()