Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
INF = float('inf')
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

H = deque(list(map(int, input().split())))
max_K = 100
for _ in range(max_K):
  H.append(INF)

dp = [INF] * (N + max_K)
dp[0] = 0

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])


Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

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

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

H = deque(list(map(int, input().split())))
max_K = 100
for _ in range(max_K):
  H.append(float('inf'))

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

for n in range(N):
  for offset in range(1, K + 1):
    cost = dp[n] + abs(H[n] - H[n + offset])
    if (dp[n + offset] > cost):
      dp[n + offset] = cost

print(dp[N - 1])


Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

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

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

H = deque(list(map(int, input().split())))
max_K = 100
for _ in range(max_K):
  H.append(float('inf'))

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

for n in range(N):
  for offset in range(1, K + 1):
    cost = dp[n] + abs(H[n] - H[n + offset])
    if (dp[n + offset] > cost):
      dp[n + offset] = cost

print(dp[N - 1])


Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

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

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, K = map(int, input().split())

H = deque(list(map(int, input().split())))
max_K = 100
for _ in range(max_K):
  H.append(float('inf'))

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

for n in range(N):
  for offset in range(1, K + 1):
    cost = dp[n] + abs(H[n] - H[n + offset])
    if (dp[n + offset] > cost):
      dp[n + offset] = cost

print(dp[N - 1])


Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

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

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, K = map(int, input().split())

H = deque(list(map(int, input().split())))
max_K = 100
for _ in range(max_K):
  H.append(float('inf'))

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

for n in range(N):
  for offset in range(1, K + 1):
    cost = dp[n] + abs(H[n] - H[n + offset])
    if (dp[n + offset] > cost):
      dp[n + offset] = cost

print(dp[N - 1])


Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

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

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])

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

H = list(map(int, input().split()))
max_K = 100
for _ in range(max_K):
  H.append(float('inf'))

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

for n in range(N):
  for offset in range(1, K + 1):
    cost = dp[n] + abs(H[n] - H[n + offset])
    if (dp[n + offset] > cost):
      dp[n + offset] = cost

print(dp[N - 1])


Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

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

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])