Buggy python submission (verdict: Time Limit Exceeded):
#参考コードでTLSにならないことを確認する
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
DP = [0]
for i in range(N-1):
    act = float("inf")
    for k in range(K):
        if i-k < 0 : continue
        act = min(DP[-1-k] + abs(h[i-k]-h[i+1]) , act)
    DP += [act]
 
print(DP[-1])

Fixed submission:
import numpy as np
#https://yottagin.com/?p=1650

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

#dp=[float("inf")]*N
#dp[0]=0
#dp=[0]
dp=np.zeros(N,dtype=int)
h=np.array(h)

for i in range(1,N):
  start=max(0,i-K)
  #start~i-1
  dp[i]=min(dp[start:i]+np.abs(h[i]-h[start:i]))
  #tmp=float("inf")
  #for k in range(1,K+1):
    #if i-k<0: break
    #dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))
    #tmp=min(tmp,dp[i-k]+abs(h[i]-h[i-k]))
  #dp[i]=tmp
  #dp+=[tmp]

print(dp[N-1])

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

#dp=[float("inf")]*N
#dp[0]=0
dp=[0]
for i in range(1,N):
  tmp=float("inf")
  for k in range(1,K+1):
    if i-k<0: break
    #dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))
    tmp=min(tmp,dp[i-k]+abs(h[i]-h[i-k]))
  #dp[i]=tmp
  dp+=[tmp]

print(dp[N-1])

Fixed submission:
import numpy as np
#https://yottagin.com/?p=1650

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

#dp=[float("inf")]*N
#dp[0]=0
#dp=[0]
dp=np.zeros(N,dtype=int)
h=np.array(h)

for i in range(1,N):
  start=max(0,i-K)
  #start~i-1
  dp[i]=min(dp[start:i]+np.abs(h[i]-h[start:i]))
  #tmp=float("inf")
  #for k in range(1,K+1):
    #if i-k<0: break
    #dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))
    #tmp=min(tmp,dp[i-k]+abs(h[i]-h[i-k]))
  #dp[i]=tmp
  #dp+=[tmp]

print(dp[N-1])

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

dp=[float("inf")]*N
dp[0]=0
for i in range(1,N):
  tmp=float("inf")
  for k in range(1,K+1):
    if i-k<0: break
    #dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))
    tmp=min(tmp,dp[i-k]+abs(h[i]-h[i-k]))
  dp[i]=tmp

print(dp[N-1])

Fixed submission:
import numpy as np
#https://yottagin.com/?p=1650

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

#dp=[float("inf")]*N
#dp[0]=0
#dp=[0]
dp=np.zeros(N,dtype=int)
h=np.array(h)

for i in range(1,N):
  start=max(0,i-K)
  #start~i-1
  dp[i]=min(dp[start:i]+np.abs(h[i]-h[start:i]))
  #tmp=float("inf")
  #for k in range(1,K+1):
    #if i-k<0: break
    #dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))
    #tmp=min(tmp,dp[i-k]+abs(h[i]-h[i-k]))
  #dp[i]=tmp
  #dp+=[tmp]

print(dp[N-1])

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

dp=[float("inf")]*N
dp[0]=0
for i in range(1,N):
  for k in range(1,K+1):
    if i-k<0: break
    dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))

print(dp[N-1])

Fixed submission:
import numpy as np
#https://yottagin.com/?p=1650

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

#dp=[float("inf")]*N
#dp[0]=0
#dp=[0]
dp=np.zeros(N,dtype=int)
h=np.array(h)

for i in range(1,N):
  start=max(0,i-K)
  #start~i-1
  dp[i]=min(dp[start:i]+np.abs(h[i]-h[start:i]))
  #tmp=float("inf")
  #for k in range(1,K+1):
    #if i-k<0: break
    #dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))
    #tmp=min(tmp,dp[i-k]+abs(h[i]-h[i-k]))
  #dp[i]=tmp
  #dp+=[tmp]

print(dp[N-1])