Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
a = list(map(int, input().split()))
dp = [0]*N


def mincos(dp, a, i, k):
    if i < k:
        mincos = 10000000000
        for j in range(1, i + 1):
            b = dp[i - j] + abs(a[i] - a[i - j])
            if mincos > b:
                mincos = b
        return mincos
    else:
        mincos = 10000000000
        for j in range(1, k + 1):
            b = dp[i - j] + abs(a[i] - a[i - j])
            if mincos > b:
                mincos = b
        return mincos


for i in range(1, N):
    dp[i] = mincos(dp, a, i, K)

print(dp[N-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)

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


print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
a = list(map(int, input().split()))
dp = []


def mincos(dp, a, i, k):
    if i == 0:
        return 0
    elif i < k:
        mincos = 10000000000
        for j in range(1, i + 1):
            b = dp[i - j] + abs(a[i] - a[i - j])
            if mincos > b:
                mincos = b
        return mincos
    else:
        mincos = 10000000000
        for j in range(1, k + 1):
            b = dp[i - j] + abs(a[i] - a[i - j])
            if mincos > b:
                mincos = b
        return mincos


for i in range(N):
    dp.append(mincos(dp, a, i, K))

print(dp[N-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)

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


print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
a = list(map(int, input().split()))
dp = []


def mincos(dp, a, i, k):
    if i == 0:
        return 0
    elif i < k:
        mincos = 10000000000
        for j in range(1, i + 1):
            if mincos > dp[i - j] + abs(a[i] - a[i - j]):
                mincos = dp[i - j] + abs(a[i] - a[i - j])
        return mincos
    else:
        mincos = 10000000000
        for j in range(1, k + 1):
            if mincos > dp[i - j] + abs(a[i] - a[i - j]):
                mincos = dp[i - j] + abs(a[i] - a[i - j])
        return mincos


for i in range(N):
    dp.append(mincos(dp, a, i, K))

print(dp[N-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)

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


print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
a = list(map(int, input().split()))
dp = []


def mincos(dp, a, i, k):
    if i == 0:
        return 0
    elif i < k:
        mincos = 100000000000
        for j in range(1, i + 1):
            if mincos > dp[i - j] + abs(a[i] - a[i - j]):
                mincos = dp[i - j] + abs(a[i] - a[i - j])
        return mincos
    else:
        mincos = 10000000000
        for j in range(1, k + 1):
            if mincos > dp[i - j] + abs(a[i] - a[i - j]):
                mincos = dp[i - j] + abs(a[i] - a[i - j])
        return mincos


for i in range(N):
    dp.append(mincos(dp, a, i, K))

print(dp[N-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)

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


print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in map(int, input().split())]
a = list(map(int, input().split()))
dp = []


def mincos(dp, a, i, k):
    if i == 0:
        return 0
    elif i < k:
        mincos = 100000000000
        for j in range(1, i + 1):
            if mincos > dp[i - j] + abs(a[i] - a[i - j]):
                mincos = dp[i - j] + abs(a[i] - a[i - j])
        return mincos
    else:
        mincos = 10000000000
        for j in range(1, k + 1):
            if mincos > dp[i - j] + abs(a[i] - a[i - j]):
                mincos = dp[i - j] + abs(a[i] - a[i - j])
        return mincos


for i in range(N):
    dp.append(mincos(dp, a, i, K))

print(dp[N-1])


Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)

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


print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in map(int, input().split())]
a = list(map(int, input().split()))
dp = []


def mincos(dp, a, i, k):
    if i == 0:
        return 0
    elif i == 1:
        return abs(a[0] - a[1])
    elif i < k:
        cos = []
        for j in range(1, i+1):
            cos.append(dp[i-j]+abs(a[i] - a[i - j]))
        return min(cos)
    else:
        cos = []
        for j in range(1, k+1):
            cos.append(dp[i - j] + abs(a[i] - a[i - j]))
        return min(cos)


for i in range(N):
    dp.append(mincos(dp, a, i, K))

print(dp[N-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)

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


print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in map(int, input().split())]
a = list(map(int, input().split()))
dp = []

for i in range(N):
    dp.append(0)


def mincos(dp, a, i, k):
    if i == 0:
        return 0
    elif i == 1:
        return abs(a[0] - a[1])
    elif i < k:
        cos = []
        for j in range(1, i+1):
            cos.append(dp[i-j]+abs(a[i] - a[i - j]))
        return min(cos)
    else:
        cos = []
        for j in range(1, k+1):
            cos.append(dp[i - j] + abs(a[i] - a[i - j]))
        return min(cos)


for i in range(N):
    dp[i] = mincos(dp, a, i, K)

print(dp[N-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.array([0] * N)

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


print(dp[-1])