Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
input = sys.stdin.readline

N, K = map(int, input().split())
H = np.array(input().split(), dtype='int32')
dp = np.zeros(N, dtype='int32')
dp[0], dp[1] = 0, abs(H[0]-H[1])

for i in range(2, N):
  dp[i] = np.min(dp[i-k] + abs(H[i]-H[i-k]) for k in range(1,K+1))
print(dp[-1])    

Fixed submission:
import sys
input = sys.stdin.readline

def cmin(a, b, i):
  if a > b:
    dp[i] = b
    return True
  return False

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [sys.maxsize]*N
dp[0] = 0

for i in range(0, N):
  for j in range(1,K+1):
    cmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]), i)
    if i > 1:
      cmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]), 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 = [sys.maxsize]*N
dp[0], dp[1] = 0, abs(H[0]-H[1])

for i in range(2, N):
  dp[i] = min(dp[i-k] + abs(H[i]-H[i-k]) for k in range(1,K+1))
print(dp[-1])    

Fixed submission:
import sys
input = sys.stdin.readline

def cmin(a, b, i):
  if a > b:
    dp[i] = b
    return True
  return False

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [sys.maxsize]*N
dp[0] = 0

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

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

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

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

for i in range(1, N):    
  for k in range(1, K+1):
    if len(H) >= abs(i-k):
      # もらうDP min(to, from)
      dp[i] = min(dp[i], dp[i-k] + abs(H[i] - H[i-k]))
print(dp[-1])    

Fixed submission:
import sys
input = sys.stdin.readline

def cmin(a, b, i):
  if a > b:
    dp[i] = b
    return True
  return False

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [sys.maxsize]*N
dp[0] = 0

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def cmin(a, b, i):
  if a > b:
    dp[i] = b
    return True
  return False

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [sys.maxsize]*N
dp[0] = 0

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

Fixed submission:
import sys
input = sys.stdin.readline

def cmin(a, b, i):
  if a > b:
    dp[i] = b
    return True
  return False

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [sys.maxsize]*N
dp[0] = 0

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

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def cmin(a, b, i):
  if a > b:
    dp[i] = b
    return True
  return False

N, K = map(int, input().split())
cost_arr = [0]*10**5
for i, num in enumerate(input().split()):
  cost_arr[i] = int(num)

dp = [sys.maxsize]*10**5
dp[0] = 0

for i in range(0, N):
  for j in range(1,K+1):
    cmin(dp[i+j], dp[i] + abs(cost_arr[i] - cost_arr[i+j]), i+j)
print(dp[N-1])    

Fixed submission:
import sys
input = sys.stdin.readline

def cmin(a, b, i):
  if a > b:
    dp[i] = b
    return True
  return False

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [sys.maxsize]*N
dp[0] = 0

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