Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.zeros(N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

Fixed submission:
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.array([0]*N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.full(N, 0)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

Fixed submission:
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.array([0]*N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int,input().split())))

cost = np.full(N, 0)
for i in range(1, N):
    gaps = np.abs(h[max(0, i-K):i] - h[i]) + cost[max(0, i-K):i]
    cost[i] = np.min(gaps)
    
print(int(cost[N-1]))

Fixed submission:
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.array([0]*N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
h = np.array([int(x) for x in input().split()])

cost = np.full(N, 0)
for i in range(1, N):
    gaps = np.abs(h[max(0, i-K):i] - h[i]) + cost[max(0, i-K):i]
    cost[i] = np.min(gaps)
    
print(int(cost[N-1]))

Fixed submission:
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.array([0]*N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

cost = np.full(N, float("inf"))
cost[0] = 0

for i in range(1, N):
    hi_cost = h[i]
    cost_list = [ abs(hi_cost - h[j]) + cost[j] for j in range(max(0, i-K), i)]
    cost[i] = min(cost_list)
    
print(int(cost[N-1]))

Fixed submission:
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.array([0]*N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

cost = np.full(N, float("inf"))
cost[0] = 0

for i in range(1, N):
    hi_cost = h[i]
    min_cost = float("inf")
    for j in range(max(0, i-K), i):
        _cost = abs(hi_cost - h[j]) + cost[j]
        min_cost = _cost if _cost < min_cost else min_cost
    cost[i] = min_cost
    
print(int(cost[N-1]))

Fixed submission:
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.array([0]*N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))