Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [1e+10 for i in range(n)]
dp[0] = 0

for i in range(0,n):
    for j in range(1,k+1):
        p = i + j
        if p < n:
            dp[p] = min(dp[p],dp[i] + abs(h[i] - h[p]))
print(dp[n-1])

Fixed submission:

INF = 2**31-1
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0

for i in range(0,n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i+j] - h[i]) + dp[i])
        else: break

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
NF = 10e7
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0

for i in range(0,n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i+j] - h[i]) + dp[i])
        else: break

print(dp[n-1])


Fixed submission:

INF = 2**31-1
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0

for i in range(0,n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i+j] - h[i]) + dp[i])
        else: break

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
import os
f = open('input.txt', 'r')
sys.stdin = f

INF = 10e5
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    for j in range(1,k+1):
        if i >= j:
            dp[i] = min(dp[i], abs(h[i] - h[i-j]) + dp[i-j])
        else: break

print(dp[n-1])


Fixed submission:

INF = 2**31-1
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0

for i in range(0,n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i+j] - h[i]) + dp[i])
        else: break

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
import os
f = open('input.txt', 'r')
sys.stdin = f

INF = 10e5
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    for j in range(1,k+1):
        if i >= j:
            dp[i] = min(dp[i], abs(h[i] - h[i-j]) + dp[i-j])
        else: break

print(dp[n-1])


Fixed submission:

INF = 2**31-1
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0

for i in range(0,n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i+j] - h[i]) + dp[i])
        else: break

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
import os
f = open('input.txt', 'r')
sys.stdin = f

INF = 10e5
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    for j in range(1,k+1):
        if i >= j:
            dp[i] = min(dp[i], abs(h[i] - h[i-j]) + dp[i-j])
        else: break

print(dp[n-1])


Fixed submission:

INF = 2**31-1
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0

for i in range(0,n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i+j] - h[i]) + dp[i])
        else: break

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):

INF = 10e5
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    cost = []
    for j in range(1,k+1):
        if i >= j:
            cost.append(abs(h[i] - h[i-j]) + dp[i-j])
        else: break
    dp[i] = min(cost)

print(dp[n-1])


Fixed submission:

INF = 2**31-1
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0

for i in range(0,n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i+j] - h[i]) + dp[i])
        else: break

print(dp[n-1])