Buggy python submission (verdict: Runtime Error):

n,k = map(int,input().split())
h = list(map(int, input().split()))

dp = [0]*n
dp[0] = 0
dp[1] = np.abs(h[0]-h[1])

for i in range(2,n):
     j = max(0,i-k)
     dp[i] = min([dp[l]+abs(h[i]-h[l]) for l in range(j,i)])

print(int(dp[n-1]))


Fixed submission:
import numpy as np
N, K = (int(i) for i in input().split())  
h = np.array([int(i) for i in input().split()])
 
dp = np.empty(N, dtype='int')
 
for i in range(N):
  if i == 0:
    dp[i] = 0
  elif i - K < 0:
    dp[i] = np.min(np.abs(h[i] - h[:i]) + dp[:i])
  else:
    dp[i] = np.min(np.abs(h[i] - h[i-K:i]) + dp[i-K:i])
 
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
h = list(map(int, input().split()))

dp = np.zeros(n)
dp[0] = 0
dp[1] = np.abs(h[0]-h[1])

for i in range(2,n):
     j = max(0,i-k)
     dp[i] = np.min([dp[l]+abs(h[i]-h[l]) for l in range(j,i)])

print(int(dp[n-1]))


Fixed submission:
import numpy as np
N, K = (int(i) for i in input().split())  
h = np.array([int(i) for i in input().split()])
 
dp = np.empty(N, dtype='int')
 
for i in range(N):
  if i == 0:
    dp[i] = 0
  elif i - K < 0:
    dp[i] = np.min(np.abs(h[i] - h[:i]) + dp[:i])
  else:
    dp[i] = np.min(np.abs(h[i] - h[i-K:i]) + dp[i-K:i])
 
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
h = list(map(int, input().split()))

dp = [0] * n
dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(2,n):
     j = max(0,i-k)
     dp[i] = min([dp[l]+abs(h[i]-h[l]) for l in range(j,i)])

print(dp[n-1])

Fixed submission:
import numpy as np
N, K = (int(i) for i in input().split())  
h = np.array([int(i) for i in input().split()])
 
dp = np.empty(N, dtype='int')
 
for i in range(N):
  if i == 0:
    dp[i] = 0
  elif i - K < 0:
    dp[i] = np.min(np.abs(h[i] - h[:i]) + dp[:i])
  else:
    dp[i] = np.min(np.abs(h[i] - h[i-K:i]) + dp[i-K:i])
 
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
h = list(map(int, input().split()))

dp = [0] * n
for i in range(k):
     dp[i]=abs(h[0]-h[i])
for i in range (k,n):
     for j in range(1,k):
          dp[i] = min(dp[i-k]+abs(h[i-k]-h[i]),dp[i-k-1]+abs(h[i-k-1]-h[i]))

print(dp[n-1])


Fixed submission:
import numpy as np
N, K = (int(i) for i in input().split())  
h = np.array([int(i) for i in input().split()])
 
dp = np.empty(N, dtype='int')
 
for i in range(N):
  if i == 0:
    dp[i] = 0
  elif i - K < 0:
    dp[i] = np.min(np.abs(h[i] - h[:i]) + dp[:i])
  else:
    dp[i] = np.min(np.abs(h[i] - h[i-K:i]) + dp[i-K:i])
 
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
import sys
setrecursionlimit(10**6)
n,k = map(int,input().split())
h = list(map(int, input().split()))

dp = [0] * n
for i in range(k):
     dp[i]=abs(h[0]-h[i])
for i in range (k,n):
     dp[i] = min([dp[i-j-1]+abs(h[i-j-1]-h[i]) for j in range(k)])

print(dp[n-1])

Fixed submission:
import numpy as np
N, K = (int(i) for i in input().split())  
h = np.array([int(i) for i in input().split()])
 
dp = np.empty(N, dtype='int')
 
for i in range(N):
  if i == 0:
    dp[i] = 0
  elif i - K < 0:
    dp[i] = np.min(np.abs(h[i] - h[:i]) + dp[:i])
  else:
    dp[i] = np.min(np.abs(h[i] - h[i-K:i]) + dp[i-K:i])
 
print(dp[N-1])

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

dp = [0] * n
for i in range(k):
     dp[i]=abs(h[0]-h[i])
for i in range (k,n):
     dp[i] = min([dp[i-j-1]+abs(h[i-j-1]-h[i]) for j in range(k)])

print(dp[n-1])


Fixed submission:
import numpy as np
N, K = (int(i) for i in input().split())  
h = np.array([int(i) for i in input().split()])
 
dp = np.empty(N, dtype='int')
 
for i in range(N):
  if i == 0:
    dp[i] = 0
  elif i - K < 0:
    dp[i] = np.min(np.abs(h[i] - h[:i]) + dp[:i])
  else:
    dp[i] = np.min(np.abs(h[i] - h[i-K:i]) + dp[i-K:i])
 
print(dp[N-1])