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

n, k = map(int, input().strip().split())
hs = np.array(list(map(int, input().strip().split())))

dp = np.zeros(n, dtype=np.int)

for i in range(1, n):
    min_cost = 1e9
    costs = [
        dp[i - j] + abs(hs[i] - hs[i - j])
        for j in range(1, min(k + 1, i + 1))
    ]
    dp[i] = min(costs)

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])

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

n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    min_cost = 1e9
    costs = [
        dp[i - j] + abs(hs[i] - hs[i - j])
        for j in range(1, min(k + 1, i + 1))
    ]
    dp[i] = min(costs)

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])

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

n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    min_cost = 1e19
    # for j in range(1, min(k + 1, i + 1)):
    #     cost = dp[i - j] + abs(hs[i] - hs[i - j])
    #     min_cost = min(cost, min_cost)
    costs = [
        dp[i - j] + abs(hs[i] - hs[i - j])
        for j in range(1, min(k + 1, i + 1))
    ]
    dp[i] = min(costs)

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])

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

n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    min_cost = 1e19
    for j in range(1, min(k + 1, i + 1)):
        cost = dp[i - j] + abs(hs[i] - hs[i - j])
        min_cost = min(cost, min_cost)
    dp[i] = min_cost

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])

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

n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    min_cost = 1e19
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            min_cost = min(cost, min_cost)
    dp[i] = min_cost

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    min_cost = 1e19
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            min_cost = min(cost, min_cost)
    dp[i] = min_cost

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
hs = list(map(int, input().split()))

# 足場 i にたどり着くまでのコストの総和の最小値
dp = [1e14] * n

dp[0] = 0
upper = min(k, n)
for i in range(1, upper):
    dp[i] = abs(hs[0] - hs[i])

if n > k:
    for i in range(k, n):
        min_cost = 1e9
        for j in range(1, k + 1):
            min_cost = min(min_cost, abs(hs[i] - hs[i - j]) + dp[i - j])
        dp[i] = min_cost

print(dp[n - 1])

Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
hs = list(map(int, input().split()))

# 足場 i にたどり着くまでのコストの総和の最小値
dp = [1e14] * n

dp[0] = 0
for i in range(1, min(k, n)):
    dp[i] = abs(hs[0] - hs[i])

if n > k:
    for i in range(k, n):
        costs = [abs(hs[i] - hs[i - j]) + dp[i - j] for j in range(1, k + 1)]
        dp[i] = min(costs)

print(dp[n - 1])

Fixed submission:
n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            cost = dp[i - j] + abs(hs[i] - hs[i - j])
            costs.append(cost)
    dp[i] = min(costs)

print(dp[n - 1])