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

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
# for i in range(1, N):
#     for j in range(1, K+1):
#         if i-j >= 0:
#             DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))

for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])

print(int(DP[-1]))

Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))

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

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
# for i in range(1, N):
#     for j in range(1, K+1):
#         if i-j >= 0:
#             DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))

for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])

print(int(DP[-1]))

Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
for i in range(1, N):
    for j in range(1, K+1):
        DP[i+j] = chmin(DP[i+j], DP[i] + abs(T[i+j] - T[i]))

print(int(DP[-1]))

Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i+j] = chmin(DP[i+j], DP[i] + abs(T[i+j] - T[i]))

print(int(DP[-1]))

Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))

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

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))

print(int(DP[-1]))

Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
for i in range(1, N):
    for j in range(1, K+1):
        DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))

print(int(DP[-1]))

Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))