Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k=map(int,input().split())
h=np.array(input().split(),np.int64)
dp=np.zeros(n+1,np.int64)
# dp[i]:足場iに到達するための最小コスト。はじめカエルは足場1にいるのでdp[1]=0
dp[1]=0
dp[2]=abs(h[0]-h[1])
for i in range(3,n+1):      
      dp[i]=np.min([dp[i-j]+abs(h[i-1]-h[i-j-1]) for j in range(1,min(k+1,i))])
print(dp[n])

Fixed submission:
n,k=map(int,input().split())
import numpy as np
h=np.array(input().split(),np.int64)
if n<3:
  print(abs(h[0]-h[1]))
  exit()
dp=np.zeros(n)
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
  j=max(0,i-k)
  dp[i]=np.min(dp[j:i]+np.abs(h[i]-h[j:i]))
  #dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k+1,i+1))])
print(int(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=np.zeros(n+1,np.int64)
# dp[i]:足場iに到達するための最小コスト。はじめカエルは足場1にいるのでdp[1]=0
dp[1]=0
dp[2]=abs(h[0]-h[1])
for i in range(3,n+1):      
      dp[i]=np.min([dp[i-j]+abs(h[i-1]-h[i-j-1]) for j in range(1,min(k+1,i))])
print(dp[n])

Fixed submission:
n,k=map(int,input().split())
import numpy as np
h=np.array(input().split(),np.int64)
if n<3:
  print(abs(h[0]-h[1]))
  exit()
dp=np.zeros(n)
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
  j=max(0,i-k)
  dp[i]=np.min(dp[j:i]+np.abs(h[i]-h[j:i]))
  #dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k+1,i+1))])
print(int(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=defaultdict(lambda:0)
# dp[i]:足場iに到達するための最小コスト。はじめカエルは足場1にいるのでdp[1]=0
dp[1]=0
dp[2]=abs(h[0]-h[1])
for i in range(3,n+1):      
      dp[i]=min([dp[i-j]+abs(h[i-1]-h[i-j-1]) for j in range(1,min(k+1,i))])
print(dp[n])


Fixed submission:
n,k=map(int,input().split())
import numpy as np
h=np.array(input().split(),np.int64)
if n<3:
  print(abs(h[0]-h[1]))
  exit()
dp=np.zeros(n)
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
  j=max(0,i-k)
  dp[i]=np.min(dp[j:i]+np.abs(h[i]-h[j:i]))
  #dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k+1,i+1))])
print(int(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
if n<3:
  print(abs(h[0]-h[1]))
  exit()
dp=[0]*(n)
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
  dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k+1,i+1))])
print(dp[-1])


Fixed submission:
n,k=map(int,input().split())
import numpy as np
h=np.array(input().split(),np.int64)
if n<3:
  print(abs(h[0]-h[1]))
  exit()
dp=np.zeros(n)
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
  j=max(0,i-k)
  dp[i]=np.min(dp[j:i]+np.abs(h[i]-h[j:i]))
  #dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k+1,i+1))])
print(int(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
if n<3:
  print(abs(h[0]-h[1]))
  exit()
dp=[0]*(n)
dp[1]=abs(h[0]-h[1])
for i in range(1,n):
  dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k+1,i+1))])
print(dp[-1])


Fixed submission:
n,k=map(int,input().split())
import numpy as np
h=np.array(input().split(),np.int64)
if n<3:
  print(abs(h[0]-h[1]))
  exit()
dp=np.zeros(n)
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
  j=max(0,i-k)
  dp[i]=np.min(dp[j:i]+np.abs(h[i]-h[j:i]))
  #dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k+1,i+1))])
print(int(dp[-1]))