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

N, K = map(int,input().split())
h = list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
  value=math.inf
  for j in range(1,K+1):
    if i-j<0:
      break
    value=min(value,dp[i-j]+abs(h[i]-h[i-j]))
  dp[i]=value
 
print(dp[N-1])

Fixed submission:
from numba import jit
import math

N, K = map(int,input().split())
h = list(map(int,input().split()))
@jit
def nya(N, K, h):
  dp=[0]*N
  for i in range(1,N):
    value=math.inf
    for j in range(1,K+1):
      if i-j<0:
        break
      value=min(value,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i]=value
  return(dp[N-1])
 
print(nya(N,K,h))

Buggy python submission (verdict: Time Limit Exceeded):
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(0,N):
  for j in range(0,K+1):
    if N<=i+j:
      break
    dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
 
print(dp[N-1])

Fixed submission:
from numba import jit
import math

N, K = map(int,input().split())
h = list(map(int,input().split()))
@jit
def nya(N, K, h):
  dp=[0]*N
  for i in range(1,N):
    value=math.inf
    for j in range(1,K+1):
      if i-j<0:
        break
      value=min(value,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i]=value
  return(dp[N-1])
 
print(nya(N,K,h))

Buggy python submission (verdict: Time Limit Exceeded):
def chmin(dp,i,x):
  if x<dp[i]:
    dp[i]=x
    return True
  return False

N, K = map(int,input().split())
h = list(map(int,input().split()))
inf = float('inf')
dp = [inf]*(110000)
dp[0]=0
for i in range(0,N):
  for j in range(1,K+1):
    if i+j<N:
      chmin(dp, i + j, dp[i] + abs(h[i] - h[i + j]))
 
print(dp[N-1])




Fixed submission:
from numba import jit
import math

N, K = map(int,input().split())
h = list(map(int,input().split()))
@jit
def nya(N, K, h):
  dp=[0]*N
  for i in range(1,N):
    value=math.inf
    for j in range(1,K+1):
      if i-j<0:
        break
      value=min(value,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i]=value
  return(dp[N-1])
 
print(nya(N,K,h))

Buggy python submission (verdict: Time Limit Exceeded):
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(1,N):
  for j in range(0,K+1):
    if 0<=i-j:
      dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]))
 
print(dp[-1])




Fixed submission:
from numba import jit
import math

N, K = map(int,input().split())
h = list(map(int,input().split()))
@jit
def nya(N, K, h):
  dp=[0]*N
  for i in range(1,N):
    value=math.inf
    for j in range(1,K+1):
      if i-j<0:
        break
      value=min(value,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i]=value
  return(dp[N-1])
 
print(nya(N,K,h))

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

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

Fixed submission:
from numba import jit
import math

N, K = map(int,input().split())
h = list(map(int,input().split()))
@jit
def nya(N, K, h):
  dp=[0]*N
  for i in range(1,N):
    value=math.inf
    for j in range(1,K+1):
      if i-j<0:
        break
      value=min(value,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i]=value
  return(dp[N-1])
 
print(nya(N,K,h))