Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = [float('inf')]*N
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])

for i in range(K+1,N):
  for j in range(0,min(i,K+1)):
    ans[i] = min(ans[i],ans[i-j]+abs(A[i]-A[i-j]))
print(ans[N-1])

Fixed submission:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
ans = np.array([float('inf')]*N)
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])
for i in range(K+1,N):
  ans[i] = min(ans[i],np.min(ans[i-K:i]+np.abs(A[i]-A[i-K:i])))
print(int(ans[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = [float('inf')]*N
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])

for i in range(K+1,N):
  for j in range(0,min(i,K+1)):
    ans[i] = min(ans[i],ans[i-j]+abs(A[i]-A[i-j]))
print(ans[N-1])

Fixed submission:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
ans = np.array([float('inf')]*N)
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])
for i in range(K+1,N):
  ans[i] = min(ans[i],np.min(ans[i-K:i]+np.abs(A[i]-A[i-K:i])))
print(int(ans[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = [float('inf')]*N
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])

for i in range(K+1,N):
  for j in range(0,min(i,K)):
    ans[i] = min(ans[i],ans[i-j]+abs(A[i]-A[i-j]), ans[i-j-1]+abs(A[i]-A[i-j-1]))
print(ans[N-1])

Fixed submission:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
ans = np.array([float('inf')]*N)
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])
for i in range(K+1,N):
  ans[i] = min(ans[i],np.min(ans[i-K:i]+np.abs(A[i]-A[i-K:i])))
print(int(ans[N-1]))

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = [float('inf')]*N
ans[0] = 0
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])

for i in range(K+1,N):
  for j in range(0,min(i,K)):
    ans[i] = min(ans[i-j]+abs(A[i]-A[i-j]), ans[i-j-1]+abs(A[i]-A[i-j-1]))
print(ans[N-1])

Fixed submission:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
ans = np.array([float('inf')]*N)
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])
for i in range(K+1,N):
  ans[i] = min(ans[i],np.min(ans[i-K:i]+np.abs(A[i]-A[i-K:i])))
print(int(ans[N-1]))

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = [float('inf')]*N
ans[0] = 0
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])

for i in range(K+1,N):
  for j in range(1,min(i,K)):
	  ans[i] = min(ans[i-j]+abs(A[i]-A[i-j]), ans[i-j-1]+abs(A[i]-A[i-j-1]))
print(ans[N-1])

Fixed submission:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
ans = np.array([float('inf')]*N)
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])
for i in range(K+1,N):
  ans[i] = min(ans[i],np.min(ans[i-K:i]+np.abs(A[i]-A[i-K:i])))
print(int(ans[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [float('inf') for i in range(N)]
dp[0] = 0
for i in range(N-1):
  for j in range(1,K+1):
    if i < N-j:
      dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j]-h[i]))
print(dp[N-1])

Fixed submission:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
ans = np.array([float('inf')]*N)
ans[0] = 0
K = min(N-1,K)
for i in range(1,K+1):
  ans[i] = abs(A[0]-A[i])
for i in range(K+1,N):
  ans[i] = min(ans[i],np.min(ans[i-K:i]+np.abs(A[i]-A[i-K:i])))
print(int(ans[N-1]))