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())))
dp = np.full(N,10**10)
dp[0] = 0
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(int(dp[-1]))

Fixed submission:
import numpy as np

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

Fixed submission:
import numpy as np

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

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

INF = float('inf')
dp = [INF] * (N)
dp[0] = 0

for i in range(1,N):
    for j in range(max(0,i-K),i):
        # print(h[j],':',h[i])
        dp[i] = min(dp[i], dp[j]+abs(h[j]-h[i]))
    # print(dp)
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.full(N,10**10)
dp[0] = 0
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = np.min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(int(dp[-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())))
dp = np.full(N,float('inf'))
dp[0] = 0
for i in range(1,N):
    for j in range(max(0,i-K),i):
        # print(h[j],':',h[i])
        dp[i] = np.fmin(dp[i], dp[j]+ np.abs(h[j]-h[i]))
    # print(dp)
print(int(dp[-1]))

Fixed submission:
import numpy as np

N,K = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.full(N,10**10)
dp[0] = 0
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = np.min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(int(dp[-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())))

dp = np.full(N,float('inf'))
dp[0] = 0

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

Fixed submission:
import numpy as np

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

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

INF = float('inf')
dp = [INF] * N
dp[0] = 0

for i in range(1,N):
    for j in range(max(0,i-K),i):
        # print(h[j],':',h[i])
        dp[i] = min(dp[i], dp[j]+abs(h[j]-h[i]))
    # print(dp)
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.full(N,10**10)
dp[0] = 0
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = np.min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(int(dp[-1]))

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

INF = float('inf')
dp = [INF] * (N)
dp[0] = 0

for i in range(1,N):
    cost = INF
    for j in range(max(0,i-K),i):
        # print(h[j],':',h[i])
        dp[i] = min(dp[i], dp[j]+abs(h[j]-h[i]))
    # print(dp)
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.full(N,10**10)
dp[0] = 0
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = np.min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(int(dp[-1]))