Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [0] + list(map(int, input().split()))
inf = 10**5
dp = [inf]*(n+1)
dp[1] = 0
dp[2] = abs(h[1] - h[2])
for i in range(3, n+1):
    dp[i] = min(
        [dp[i-j] + abs(h[i-j] - h[i]) for j in range(1, min(k, i)+1)]
    )
print(dp[n])

Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy python submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.zeros((N+1, K+1), dtype=int)
for i in range(1, N):
    for k in range(1, K+1):
        if i >= k:
            dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k][1:K + 1])
        else:
            w = i
            dp[i+1][k] = dp[i+1][k-1]
print(min(dp[N][1:K+1]))

Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy python submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.full((N+1, K+1), np.inf, dtype=float)
dp[1] = np.zeros(K+1)
for i in range(1, N):
    k = 1
    while i >= k >= 0:
        dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k])
        k += 1
print(int(min(dp[N])))

Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy python submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.full((N+1, K+1), np.inf, dtype=float)
dp[1] = np.zeros(K+1)
for i in range(1, N):
    k = 1
    while i >= k >= 0:
        dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k])
        k += 1
print(int(min(dp[N])))




Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.full((N+1, K+1), np.inf, dtype=float)
dp[1] = np.zeros(K+1)
for i in range(1, N):
    k = 1
    while i >= k and k <= K:
        dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k])
        k += 1
print(int(min(dp[N])))




Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy python submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.full((N+1, K+1), np.inf, dtype=float)
dp[1] = np.zeros(K+1)
for i in range(1, N):
    k = 1
    while i >= k:
        dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k][1:K + 1])
        k += 1
print(int(min(dp[N][1:K+1])))




Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.zeros((N+1, K+1), dtype=int)
for i in range(1, N):
    for k in range(1, K+1):
        if i >= k:
            dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k][1:K + 1])
        else:
            w = i
            dp[i+1][k] = dp[i+1][k-1]
print(min(dp[N][1:K+1]))




Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy python submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.zeros(N+1, dtype=int)
for i in range(1, N):
    if i >= k:
        dp[i+1] = min(
            [
                abs(h[i]-h[i-k]) + dp[i+1-k]
                for k in range(1, K+1)
            ]
        )
    else:
        dp[i + 1] = min(
            [
                abs(h[i] - h[i - k]) + dp[i + 1 - k]
                for k in range(1, i + 1)
            ]
        )
print(dp[N])

Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.zeros(N+1, dtype=int)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])