Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = map(int, input().split(' '))
h = list(map(int, input().split(' ')))
dp = [float('inf')]*(len(h))
dp[0] = 0
for i in range(1, len(h)):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), 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.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(' '))
h = list(map(int, input().split(' ')))
dp = [float('inf')]*(len(h))
dp[0] = 0
for i in range(1, len(h)):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), 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.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(' '))
h = list(map(int, input().split(' ')))
dp = [0] + [float('inf')]*(len(h)-1)
for i in range(1, len(h)):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), 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.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split(' '))
h = [int(val) for val in input().split(' ')]
if len(h) == 0:
    return 0
dp = [0] + [float('inf')]*(len(h)-1)
for i in range(1, len(h)):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), 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.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(' '))
h = [int(val) for val in input().split(' ')]
dp = [0] + [float('inf')]*(len(h)-1)
for i in range(1, len(h)):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), 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.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])

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

Fixed submission:
import numpy as np

N, K = map(int, input().split(' '))
h = np.array(list(map(int, input().split(' '))))
dp = np.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(' '))
h = [int(val) for val in input().split(' ')]
dp = [0]

for i in range(1, len(h)):
    min_cost = float('inf')
    for j in range(min(i, K)):
        cost = dp[i-j-1] + abs(h[i]-h[i-j-1])
        if cost < min_cost:
            min_cost = cost
    dp.append(min_cost)
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.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(' '))
h = [int(val) for val in input().split(' ')]
dp = [0]

for i in range(1, len(h)):
    dp.append(min([dp[i-j-1] + abs(h[i]-h[i-j-1]) for j in range(min(i, K))]))
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.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])