Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
sys.setrecursionlimit(20000000)
INF = float('inf')

N, K = map(int, input().split())
h = list(map(int, input().split()))
n = len(h)-1

@lru_cache(maxsize=None)
def rec(i):
    if i==0:
        return 0
    res = INF
    for j in range(1,K+1):
        if i-j>=0:
            res = min(res, rec(i-j)+abs(h[i]-h[i-j]))
    return res
print(rec(n))

Fixed submission:
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
MAX_N = 10**5+100
INF = float('inf')

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

# dp table
# dp[i] := 足場iに行くのにかかる最小のコスト
dp = [INF]*MAX_N
dp[0] = 0

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

Fixed submission:
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
class T():
    def __init__(self, values):
        self.values = values

    def __add__(self, x):
        return min(self.values, x.values)

    def __mul__(self, x):
        return self.values + x.values

    def Tropical_sum(self):
        return min(self.values)
inf = float('inf')

# input
N, K = map(int, input().split())
h = list(map(int, input().split()))

# dp table
dp = [inf]*N
dp[0] = 0

for i in range(N):
    for j in range(1,K+1):
        if i-j>=0:
            dp[i] = T(dp[i]) + T(dp[i-j] + abs(h[i]-h[i-j]))
print(dp[N-1])

Fixed submission:
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

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

# dp table
INF = float('inf')
dp = [INF]*N
dp[0] = 0

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

Fixed submission:
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

Fixed submission:
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * (10**5 + 10000)
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

Fixed submission:
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * (10)
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])

Fixed submission:
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])