Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

import numpy as np

N, K = map(int, readline().split())
H = np.array(readline().split(), dtype=np.int64)

# dp = [INF] * N
dp = np.ones(N, dtype=np.int64)*float("inf")
dp[0] = 0

# 配るDP
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i] - H[i+j]))
    
ans = int(dp[-1])
print(ans)

Fixed submission:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, K = map(int, readline().split())
H = list(map(int, readline().split()))

dp = [INF] * N
dp[0] = 0

# 配るDP
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i] - H[i+j]))
    
ans = dp[-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

import numpy as np

N, K = map(int, readline().split())
H = np.array(readline().split(), dtype=np.int64)

dp = [INF] * N
dp[0] = 0

# 配るDP
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i] - H[i+j]))
    
ans = dp[-1]
print(ans)

Fixed submission:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, K = map(int, readline().split())
H = list(map(int, readline().split()))

dp = [INF] * N
dp[0] = 0

# 配るDP
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i] - H[i+j]))
    
ans = dp[-1]
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

import numpy as np

N, K = map(int, readline().split())
H = np.array(readline().split(), dtype=np.int64)

dp = [INF] * N
dp[0] = 0

# 配るDP
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i] - H[i+j]))
    
ans = dp[-1]
print(ans)

Fixed submission:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, K = map(int, readline().split())
H = list(map(int, readline().split()))

dp = [INF] * N
dp[0] = 0

# 配るDP
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i] - H[i+j]))
    
ans = dp[-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, K = map(int, readline().split())
H = list(map(int, readline().split()))

dp = [INF] * N
dp[0] = 0

# 配るDP
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i] - H[i+j]))
    
ans = dp[-1]
print(ans)

Fixed submission:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, K = map(int, readline().split())
H = list(map(int, readline().split()))

dp = [INF] * N
dp[0] = 0

# 配るDP
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i] - H[i+j]))
    
ans = dp[-1]
print(ans)