Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit
setrecursionlimit(1000000) 
N, K = list(map(int, input().split()))
H = [int(v) for v in stdin.readline().strip().split(' ')]

def memoize(length):
    def _memoize(f):
        cache = [-1] * length
        def helper(x):
            if cache[x] == -1:
                cache[x] = f(x)
            return cache[x]
        return helper
    return _memoize


@memoize(N)
def jump(i):
    if i == 0:
        return 0
    mn = int(10 ** 9)
    for j in range(1, K + 1):
        if i - j >= 0:
            mn = min(mn, abs(H[i] - H[i - j]) + jump(i - j))
    return mn

print(jump(N - 1))



Fixed submission:
import sys
import numpy as np

N, K = [int(v) for v in input().strip().split(' ')]

H = np.array([int(v) for v in sys.stdin.readline().strip().split(' ')])

dp = np.zeros(N, dtype=int)

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

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import setrecursionlimit
setrecursionlimit(1000000) 
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

def memoize(f):
    cache = {}
    def helper(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]
    return helper


@memoize
def jump(i):
    if i == 0:
        return 0
    mn = int(10 ** 9)
    for j in range(1, K + 1):
        if i - j >= 0:
            mn = min(mn, abs(H[i] - H[i - j]) + jump(i - j))
    return mn

print(jump(N - 1))




Fixed submission:
import sys
import numpy as np

N, K = [int(v) for v in input().strip().split(' ')]

H = np.array([int(v) for v in sys.stdin.readline().strip().split(' ')])

dp = np.zeros(N, dtype=int)

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

print(dp[-1])

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

def memoize(f):
    cache = {}
    def helper(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]
    return helper


@memoize
def jump(i):
    if i == 0:
        return 0
    mn = int(10 ** 9)
    for j in range(1, K + 1):
        if i - j >= 0:
            mn = min(mn, abs(H[i] - H[i - j]) + jump(i - j))
    return mn

print(jump(N - 1))

Fixed submission:
import sys
import numpy as np

N, K = [int(v) for v in input().strip().split(' ')]

H = np.array([int(v) for v in sys.stdin.readline().strip().split(' ')])

dp = np.zeros(N, dtype=int)

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

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):

import sys

N, K = [int(v) for v in input().strip().split(' ')]

H = [int(v) for v in sys.stdin.readline().strip().split(' ')]

dp = [int(10 ** 10)] * N

dp[0] = 0
dp[1] = abs(H[0] - H[1])

for i in range(2, N):
    for k in range(1, K + 1):
        if i - k >= 0:
            dp[i] = min(dp[i], dp[i - k] + abs(H[i] - H[i - k]))

print(dp[-1])




Fixed submission:
import sys
import numpy as np

N, K = [int(v) for v in input().strip().split(' ')]

H = np.array([int(v) for v in sys.stdin.readline().strip().split(' ')])

dp = np.zeros(N, dtype=int)

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

print(dp[-1])

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

H = [int(v) for v in input().strip().split(' ')]

dp = [int(10 ** 10)] * N

dp[0] = 0
dp[1] = abs(H[0] - H[1])

for i in range(2, N):
    for k in range(1, K + 1):
        if i - k >= 0:
            dp[i] = min(dp[i], dp[i - k] + abs(H[i] - H[i - k]))

print(dp[-1])



Fixed submission:
import sys
import numpy as np

N, K = [int(v) for v in input().strip().split(' ')]

H = np.array([int(v) for v in sys.stdin.readline().strip().split(' ')])

dp = np.zeros(N, dtype=int)

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

print(dp[-1])