Buggy python submission (verdict: Runtime Error):
import numpy as np
import math

def solve():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0]*(n+5)
    for i in range(1,n):
        dp[i] = min([
            [dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)]
            ])
    print(dp[n-1])
    return 0
 
if __name__ == "__main__":
    solve()


Fixed submission:
def hoge():
  dp = [0] * (n + 5)
  for i in range(1, n):
    p = [dp[j] + abs(h_list[i] - h_list[j]) for j in range(max(0, i - k), i)]
    dp[i] = min(p)
  return dp[n - 1]

def solve():
  global n, k, h_list
  n, k = map(int, input().split())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()

Buggy python submission (verdict: Runtime Error):
import numpy as np
import math

def solve():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0]*(n+5)
    for i in range(1,n):
        dp[i] = min([
            [dp[j]+abs(h[i]-h[j]) for i in range(max(0,i-k),i)]
            ])
    print(dp[n-1])
    return 0
 
if __name__ == "__main__":
    solve()


Fixed submission:
def hoge():
  dp = [0] * (n + 5)
  for i in range(1, n):
    p = [dp[j] + abs(h_list[i] - h_list[j]) for j in range(max(0, i - k), i)]
    dp[i] = min(p)
  return dp[n - 1]

def solve():
  global n, k, h_list
  n, k = map(int, input().split())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
import scipy

def hoge():
  dp = [0] * (n + 5)
  for i in range(1, n):
    p = [dp[j] + abs(h_list[i] - h_list[j]) for j in range(max(0, i - k), i)]
    dp[i] = min(p)
  return dp[n - 1]

def solve():
  global n, k, h_list
  n, k = map(int, input().split())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()

Fixed submission:
def hoge():
  dp = [0] * (n + 5)
  for i in range(1, n):
    p = [dp[j] + abs(h_list[i] - h_list[j]) for j in range(max(0, i - k), i)]
    dp[i] = min(p)
  return dp[n - 1]

def solve():
  global n, k, h_list
  n, k = map(int, input().split())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()

Buggy python submission (verdict: Runtime Error):
import numpy as np
import math
import scipy

def hoge():
  dp = [0] * (n + 5)
  for i in range(1, n):
    if i <= k:
      p = i
    else:
      p = k
    dp[i] = min(dp[i] + abs(h_list[i] - h_list[j]) for j in range(p, i))
  return dp[n]

def solve():
  global n, k, h_list
  n, k = map(int, input().split())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()

Fixed submission:
def hoge():
  dp = [0] * (n + 5)
  for i in range(1, n):
    p = [dp[j] + abs(h_list[i] - h_list[j]) for j in range(max(0, i - k), i)]
    dp[i] = min(p)
  return dp[n - 1]

def solve():
  global n, k, h_list
  n, k = map(int, input().split())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()