Buggy python submission (verdict: Time Limit Exceeded):
import sys; input = sys.stdin.buffer.readline
import numpy as np
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	h = np.array(getlist() + [0] * K, dtype = np.int64)
	
	DP = [INF for i in range(N + K)]
	DP[0] = 0

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

	print(DP[N - 1])

if __name__ == '__main__':
	main()

Fixed submission:
import sys; input = sys.stdin.buffer.readline
import numpy as np
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = 2 ** 63 - 1

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	h = np.array(getlist() + [0] * K, dtype = np.int64)
	
	DP = np.full(N + K, INF, dtype = np.int64)
	DP[0] = 0
	for i in range(N):
		DP[i + 1:i + K + 1] = np.minimum(DP[i + 1:i + K + 1],
			DP[i] + np.abs(h[i] - h[i + 1:i + K + 1]))

	print(DP[N - 1])

if __name__ == '__main__':
	main()

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

L = [float("inf") for i in range(N)]
L[0] = 0

for i in range(N):
    for j in range(min(N - i - 1, K)):
        x = L[i] + abs(h[i] - h[i + j + 1])
        if L[i + j + 1] > x:
            L[i + j + 1] = x

print(L[N - 1])

Fixed submission:
import sys; input = sys.stdin.buffer.readline
import numpy as np
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = 2 ** 63 - 1

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	h = np.array(getlist() + [0] * K, dtype = np.int64)
	
	DP = np.full(N + K, INF, dtype = np.int64)
	DP[0] = 0
	for i in range(N):
		DP[i + 1:i + K + 1] = np.minimum(DP[i + 1:i + K + 1],
			DP[i] + np.abs(h[i] - h[i + 1:i + K + 1]))

	print(DP[N - 1])

if __name__ == '__main__':
	main()

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

L = [float("inf") for i in range(N)]
for i in range(min(N, K)):
    L[i] = abs(h[0] - h[i])


for i in range(N):
    for j in range(min(N - i - 1, K)):
        x = L[i] + abs(h[i] - h[i + j + 1])
        if L[i + j + 1] > x:
            L[i + j + 1] = x

print(L[N - 1])

Fixed submission:
import sys; input = sys.stdin.buffer.readline
import numpy as np
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = 2 ** 63 - 1

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	h = np.array(getlist() + [0] * K, dtype = np.int64)
	
	DP = np.full(N + K, INF, dtype = np.int64)
	DP[0] = 0
	for i in range(N):
		DP[i + 1:i + K + 1] = np.minimum(DP[i + 1:i + K + 1],
			DP[i] + np.abs(h[i] - h[i + 1:i + K + 1]))

	print(DP[N - 1])

if __name__ == '__main__':
	main()

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

L = [float("inf") for i in range(N)]
for i in range(min(N, K)):
    L[i] = abs(h[0] - h[i])


for i in range(K, N):
    X = []
    
    for j in range(K):
        x = L[i - j - 1] + abs(h[i] - h[i - j - 1])
        X.append(x)
    
    L[i] = min(X)

print(L[N - 1])

Fixed submission:
import sys; input = sys.stdin.buffer.readline
import numpy as np
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = 2 ** 63 - 1

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	h = np.array(getlist() + [0] * K, dtype = np.int64)
	
	DP = np.full(N + K, INF, dtype = np.int64)
	DP[0] = 0
	for i in range(N):
		DP[i + 1:i + K + 1] = np.minimum(DP[i + 1:i + K + 1],
			DP[i] + np.abs(h[i] - h[i + 1:i + K + 1]))

	print(DP[N - 1])

if __name__ == '__main__':
	main()