Buggy python submission (verdict: Runtime Error):
import numpy as np
def inpl(): return list(map(int, sys.stdin.readline().split()))
INF = float('inf')

N,K = inpl()

hlist = np.array(inpl())

dp = np.full(N,INF)

dp[0]=0

for i in range(1,N):
    s = max(0,i-K)
    dp[i] = np.min(dp[s:i]+abs(hlist[i]-hlist[s:i]))

print(int(dp[N-1]))


Fixed submission:
import numpy as np
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
INF = float('inf')

N,K = inpl()

hlist = np.array(inpl())

dp = np.full(N,INF)

dp[0]=0

for i in range(1,N):
    s = max(0,i-K)
    dp[i] = np.min(dp[s:i]+abs(hlist[i]-hlist[s:i]))

print(int(dp[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,copy,heapq
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

N,K = inpl()

hlist = inpl()

dp = [INF for _ in range(N)]

dp[0]=0

for i in range(1,N):
    for j in range(1,K+1):
        if i-j < 0:
            break
        dp[i]=min(dp[i-j]+abs(hlist[i]-hlist[i-j]),dp[i])


print(dp[N-1])


Fixed submission:
import numpy as np
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
INF = float('inf')

N,K = inpl()

hlist = np.array(inpl())

dp = np.full(N,INF)

dp[0]=0

for i in range(1,N):
    s = max(0,i-K)
    dp[i] = np.min(dp[s:i]+abs(hlist[i]-hlist[s:i]))

print(int(dp[N-1]))

Buggy python submission (verdict: Runtime Error):
import sys,queue,copy,heapq
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

N,K = inpl()

hlist = inpl()

dp = [INF for _ in range(N)]

dp[0]=0

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


print(dp[N-1][0])


Fixed submission:
import numpy as np
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
INF = float('inf')

N,K = inpl()

hlist = np.array(inpl())

dp = np.full(N,INF)

dp[0]=0

for i in range(1,N):
    s = max(0,i-K)
    dp[i] = np.min(dp[s:i]+abs(hlist[i]-hlist[s:i]))

print(int(dp[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,copy,heapq
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

N,K = inpl()

hlist = inpl()

dp = [[] for _ in range(N)]
heapq.heapify(dp)


for i in range(N):
    if i == 0 :
        heapq.heappush(dp[i],0)
        continue
    for j in range(1,K+1):
        if i-j < 0:
            break
        heapq.heappush(dp[i],(dp[i-j][0]+abs(hlist[i]-hlist[i-j])))

print(dp[N-1][0])


Fixed submission:
import numpy as np
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
INF = float('inf')

N,K = inpl()

hlist = np.array(inpl())

dp = np.full(N,INF)

dp[0]=0

for i in range(1,N):
    s = max(0,i-K)
    dp[i] = np.min(dp[s:i]+abs(hlist[i]-hlist[s:i]))

print(int(dp[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,copy,heapq
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

N,K = inpl()

hlist = inpl()

dp = [[] for _ in range(N)]
for i in range(N):
    heapq.heapify(dp[i])


for i in range(N):
    if i == 0 :
        heapq.heappush(dp[i],0)
        continue
    for j in range(1,K+1):
        if i-j < 0:
            break
        heapq.heappush(dp[i],(dp[i-j][0]+abs(hlist[i]-hlist[i-j])))

print(dp[N-1][0])


Fixed submission:
import numpy as np
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
INF = float('inf')

N,K = inpl()

hlist = np.array(inpl())

dp = np.full(N,INF)

dp[0]=0

for i in range(1,N):
    s = max(0,i-K)
    dp[i] = np.min(dp[s:i]+abs(hlist[i]-hlist[s:i]))

print(int(dp[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

N,K = inpl()

hlist = inpl()

dp = [INF]*N

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

print(dp[N-1])


Fixed submission:
import numpy as np
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
INF = float('inf')

N,K = inpl()

hlist = np.array(inpl())

dp = np.full(N,INF)

dp[0]=0

for i in range(1,N):
    s = max(0,i-K)
    dp[i] = np.min(dp[s:i]+abs(hlist[i]-hlist[s:i]))

print(int(dp[N-1]))