Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
inputs = [int(i) for i in input().split()]

dp = [0 for _ in range(N)]
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = min(dp[j] + abs(inputs[j] - inputs[i]) for j in range(start, i))

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 = map(int, input().split())
inputs = [int(i) for i in input().split()]

dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = min(dp[j] + abs(inputs[j] - inputs[i]) for j in range(start, i))

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 = map(int, input().split())
inputs = [int(i) for i in input().split()]

dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = abs(inputs[i] - inputs[i-1])
    else:
        tmp = 10 ** 9
        start = max(0, i-K)
        dp[i] = min(dp[j] + abs(inputs[j] - inputs[i]) for j in range(start, i))

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 = map(int, input().split())
inputs = [int(i) for i in input().split()]

dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = abs(inputs[i] - inputs[i-1])
    else:
        tmp = 10 ** 9
        start = max(0, i-K)
        dp[i] = min([dp[j] + abs(inputs[j] - inputs[i]) for j in range(start, i)])

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: Runtime Error):
N, K = map(int, input().split())
inputs = [int(i) for i in input().split()]

dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = abs(inputs[i] - inputs[i-1])
    else:
        tmp = 10 ** 9
        start = max(0, i-K)
        dp[i] = min([dp[start] + abs(inputs[i-(j+1)] - inputs[i]) for j in range(start, i-1)])

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 = map(int, input().split())
inputs = [int(i) for i in input().split()]

dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = abs(inputs[i] - inputs[i-1])
    else:
        tmp = 10 ** 9
        count = 0
        for j in range(i):
            if count >= K or i - (j + 1) < 0:
                break
            tmp = min(tmp, dp[i-(j+1)] + abs(inputs[i] - inputs[i-(j+1)]))
            count += 1
        dp[i] = tmp

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 = map(int, input().split())
inputs = [int(i) for i in input().split()]

dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = abs(inputs[i] - inputs[i-1])
    else:
        tmp = 10 ** 9
        count = 0
        for j in range(i):
            if count >= K:
                break
            tmp = min(tmp, dp[i-(j+1)] + abs(inputs[i] - inputs[i-(j+1)]))
            count += 1
        dp[i] = tmp

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])