Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  N, K = list(map(int, input().split(" ")))
  h = input().split(" ")
  h = [int(number) for number in h]

  minimumCostToReach = [0 for i in range(N)]

  minimumCostToReach[0] = 0
  for currentIndex in range(1, N):
    minimumCostToReach[currentIndex] = 1000000000

    for previousIndex in range(max(currentIndex - K, 0), currentIndex):
      cost = minimumCostToReach[previousIndex] + abs(h[currentIndex] - h[previousIndex])
      minimumCostToReach[currentIndex] = min(minimumCostToReach[currentIndex], cost)

  print(minimumCostToReach[N - 1])

solve()

Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [0] * N

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

print(dp[N - 1])


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

minimumCost = [0] * N

for currentIndex in range(1, N):
  minimumCost[currentIndex] = min(minimumCost[previousIndex] + abs(h[currentIndex] - h[previousIndex]) for previousIndex in range(max(currentIndex - K, 0), currentIndex))

print(minimumCost[N - 1])


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  N, K = [int(i) for i in input().split()]
  h = [int(i) for i in input().split()]

  minimumCost = [0] * N

  for currentIndex in range(1, N):
    minimumCost[currentIndex] = min(minimumCost[previousIndex] + abs(h[currentIndex] - h[previousIndex]) for previousIndex in range(max(currentIndex - K, 0), currentIndex))

  return minimumCost[N - 1]

print(solve())


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

minimumCost = [0] * N

for currentIndex in range(1, N):
  minimumCost[currentIndex] = min(minimumCost[previousIndex] + abs(h[currentIndex] - h[previousIndex]) for previousIndex in range(max(currentIndex - K, 0), currentIndex))

print(minimumCost[N - 1])


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

minimumCost = [0 for i in range(N)]

minimumCost[0] = 0
for currentIndex in range(1, N):
  minimumCost[currentIndex] = min(minimumCost[previousIndex] + abs(h[currentIndex] - h[previousIndex]) for previousIndex in range(max(currentIndex - K, 0), currentIndex))

print(minimumCost[N - 1])


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split(" ")))
h = input().split(" ")
h = [int(number) for number in h]

minimumCostToReach = [0 for i in range(N)]

minimumCostToReach[0] = 0
for currentIndex in range(1, N):
  minimumCostToReach[currentIndex] = 1000000000

  for previousIndex in range(max(currentIndex - K, 0), currentIndex):
    cost = minimumCostToReach[previousIndex] + abs(h[currentIndex] - h[previousIndex])
    minimumCostToReach[currentIndex] = min(minimumCostToReach[currentIndex], cost)

print(minimumCostToReach[N - 1])


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

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

minimumCostToReach = [0] * N

minimumCostToReach[0] = 0
for currentIndex in range(1, N):
  minimumCostToReach[currentIndex] = 1000000000

  for previousIndex in range(max(currentIndex - K, 0), currentIndex):
    cost = minimumCostToReach[previousIndex] + abs(h[currentIndex] - h[previousIndex])
    minimumCostToReach[currentIndex] = min(minimumCostToReach[currentIndex], cost)

print(minimumCostToReach[N - 1])


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

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

minimumCostToReach = [0 for i in range(N)]

minimumCostToReach[0] = 0
for currentIndex in range(1, N):
  minimumCostToReach[currentIndex] = 1000000000

  for previousIndex in range(max(currentIndex - K, 0), currentIndex):
    cost = minimumCostToReach[previousIndex] + abs(h[currentIndex] - h[previousIndex])
    minimumCostToReach[currentIndex] = min(minimumCostToReach[currentIndex], cost)

print(minimumCostToReach[N - 1])


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())

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

minimumCostToReach = [0 for i in range(N)]

minimumCostToReach[0] = 0
for currentIndex in range(1, N):
  minimumCostToReach[currentIndex] = 1000000000

  previousIndex = currentIndex - 1
  while previousIndex >= 0 and previousIndex + K >= currentIndex:
    cost = minimumCostToReach[previousIndex] + abs(h[currentIndex] - h[previousIndex])
    minimumCostToReach[currentIndex] = min(minimumCostToReach[currentIndex], cost)
    previousIndex -= 1

print(minimumCostToReach[N - 1])


Fixed submission:
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())