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

dp = np.array([0] * N)
candi = np.array([0] * N)

for i in range(1, N):
	j = max(0, i-K)
	candi[j:i] = dp[j:i] + np.abs(h[i] - h[j:i])
	dp[i] = candi[j:i].min()

print(dp[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)
#candi = np.array([0] * N)

for i in range(1, N):
	j = max(0, i-K)
	#print()
	#candi[j:i] = dp[j:i] + np.abs(h[i] - h[j:i])
	dp[i] = (dp[j:i] + np.abs(h[i] - h[j:i])).min()
	#print('j,i=',j,i)
	#print('dp[j:i]=',dp[j:i])
	#print('np.abs(h[i] - h[j:i]) = ', np.abs(h[i] - h[j:i]) )		
	#print('candi[j:i]=',candi[j:i])
	#dp[i] = candi[j:i].min()
	#print('dp=',dp)
				
print(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 = [0] + [1000000000] * (N-1)

h = np.array(h)
dp = np.array(dp)

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

print(dp[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)
#candi = np.array([0] * N)

for i in range(1, N):
	j = max(0, i-K)
	#print()
	#candi[j:i] = dp[j:i] + np.abs(h[i] - h[j:i])
	dp[i] = (dp[j:i] + np.abs(h[i] - h[j:i])).min()
	#print('j,i=',j,i)
	#print('dp[j:i]=',dp[j:i])
	#print('np.abs(h[i] - h[j:i]) = ', np.abs(h[i] - h[j:i]) )		
	#print('candi[j:i]=',candi[j:i])
	#dp[i] = candi[j:i].min()
	#print('dp=',dp)
				
print(dp[-1])

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

dp = [0] + [1000000000] * (N-1)

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

print(dp[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)
#candi = np.array([0] * N)

for i in range(1, N):
	j = max(0, i-K)
	#print()
	#candi[j:i] = dp[j:i] + np.abs(h[i] - h[j:i])
	dp[i] = (dp[j:i] + np.abs(h[i] - h[j:i])).min()
	#print('j,i=',j,i)
	#print('dp[j:i]=',dp[j:i])
	#print('np.abs(h[i] - h[j:i]) = ', np.abs(h[i] - h[j:i]) )		
	#print('candi[j:i]=',candi[j:i])
	#dp[i] = candi[j:i].min()
	#print('dp=',dp)
				
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] + [1000000000] * (N-1)

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

print(dp[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)
#candi = np.array([0] * N)

for i in range(1, N):
	j = max(0, i-K)
	#print()
	#candi[j:i] = dp[j:i] + np.abs(h[i] - h[j:i])
	dp[i] = (dp[j:i] + np.abs(h[i] - h[j:i])).min()
	#print('j,i=',j,i)
	#print('dp[j:i]=',dp[j:i])
	#print('np.abs(h[i] - h[j:i]) = ', np.abs(h[i] - h[j:i]) )		
	#print('candi[j:i]=',candi[j:i])
	#dp[i] = candi[j:i].min()
	#print('dp=',dp)
				
print(dp[-1])

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

dp = [0] + [1000000000] * (N-1)

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

print(dp[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)
#candi = np.array([0] * N)

for i in range(1, N):
	j = max(0, i-K)
	#print()
	#candi[j:i] = dp[j:i] + np.abs(h[i] - h[j:i])
	dp[i] = (dp[j:i] + np.abs(h[i] - h[j:i])).min()
	#print('j,i=',j,i)
	#print('dp[j:i]=',dp[j:i])
	#print('np.abs(h[i] - h[j:i]) = ', np.abs(h[i] - h[j:i]) )		
	#print('candi[j:i]=',candi[j:i])
	#dp[i] = candi[j:i].min()
	#print('dp=',dp)
				
print(dp[-1])

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

dp = [0] + [1000000000] * (N-1)

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

print(dp[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)
#candi = np.array([0] * N)

for i in range(1, N):
	j = max(0, i-K)
	#print()
	#candi[j:i] = dp[j:i] + np.abs(h[i] - h[j:i])
	dp[i] = (dp[j:i] + np.abs(h[i] - h[j:i])).min()
	#print('j,i=',j,i)
	#print('dp[j:i]=',dp[j:i])
	#print('np.abs(h[i] - h[j:i]) = ', np.abs(h[i] - h[j:i]) )		
	#print('candi[j:i]=',candi[j:i])
	#dp[i] = candi[j:i].min()
	#print('dp=',dp)
				
print(dp[-1])