Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = [int(i) for i in input().split()]

dp = [0] * n

steps = np.array([int(i) for i in input().split()])

for i in range(1, n):
    start = max(0, i-k)
    dp[i] = (dp[start:i] + abs(steps[i] - steps[start:i])).min()

print(dp[-1])

Fixed submission:
import numpy as np
 
 
N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])
 
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()
 
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(i) for i in input().split()]

steps = [int(i) for i in input().split()]
dp = [9999999] * n

dp[0] = 0

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

print(dp[n - 1])

Fixed submission:
import numpy as np
 
 
N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])
 
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()
 
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,k = [int(i) for i in input().split()]

steps = [int(i) for i in input().split()]
dp = [9999999] * n

dp[0] = 0

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

print(dp[n - 1])

Fixed submission:
import numpy as np
 
 
N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])
 
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()
 
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,k = [int(i) for i in input().split()]

steps = [int(i) for i in input().split()]
dp = ['inf'] * n

for i in range(1, n):
    start = max(0, i-k)
    dp[i] = (dp[start:i] + abs(steps[i] - steps[start:i])).min()

print(dp[n - 1])

Fixed submission:
import numpy as np
 
 
N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])
 
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()
 
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(i) for i in input().split()]

steps = [int(i) for i in input().split()]
dp = ['inf'] * n

dp[0] = 0

for i in range(1, n):
    temp = []
    for j in range(1, k + 1):
        if i - j >= 0:
            temp.append(dp[i-j] + abs(steps[i] - steps[i-j]))
        else:
            continue
    dp[i] = min(temp)

print(dp[n - 1])

Fixed submission:
import numpy as np
 
 
N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])
 
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()
 
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k = [int(i) for i in input().split()]

steps = [int(i) for i in input().split()]
dp = [999999] * n

if n <= k:
    print(abs(steps[0] - steps[n-1]))
    sys.exit()

for i in range(k):
    dp[i] = abs(steps[0] - steps[i])

for i in range(k, n):
    temp = []
    for j in range(1, k + 1):
            temp.append(dp[i-j] + abs(steps[i] - steps[i-j]))
    dp[i] = min(temp)

print(dp[n-1])

Fixed submission:
import numpy as np
 
 
N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])
 
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()
 
print(dp[-1])