Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, K):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    print(dp)
print(dp[N-1])


Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])

dp = np.full(N+1, 10**10+1, dtype='int64')
dp[0] = 0

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

    # print(dp)
print(dp[N-1])


Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])

dp = np.array([10**10+1 for _ in range(N+1)])
dp[0] = 0

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

    # print(dp)
print(dp[N-1])

Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])

dp = np.full(N+1, 10**10+1, dtype='int64')
dp[0] = 0

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

    # print(dp)
print(dp[N-1])

Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])

dp = np.full(N+1, 10**5)
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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


Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])

dp = np.full(N+1, 10**5)
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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


Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])

dp = np.full(N+1, 10**5)
dp[1] = abs(h[1] - h[0])

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


Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = [int(item) for item in input().split()]
h =[0] + [int(item) for item in input().split()]

dp = [0 for _ in range(N+1)]

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


Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(item) for item in input().split()]
h =[0] + [int(item) for item in input().split()]

dp = [0 for _ in range(N+1)]

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

Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N, K = [int(item) for item in input().split()]
h =[0] + [int(item) for item in input().split()]

dp = [0 for _ in range(N+1)]

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

print(dp[1+N - K])

Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N, K = [int(item) for item in input().split()]
h =[0] + [int(item) for item in input().split()]

dp = [0 for _ in range(N+1)]
dp[2]= abs(h[2] - h[1])

for i in range(3, N):
    for k in range(1,K+1):
        # print(i,k, dp[i])
        if dp[i] != 0:
            if 2 <= i-k:
                dp[i] = min(dp[i], dp[i-k] + abs(h[i-k] - h[i]))
        else:
            # print('make')
            if 2 <= i-k:
                dp[i] = dp[i-k] + abs(h[i-k] - h[i])

print(dp[1+N-K])

Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N, K = [int(item) for item in input().split()]
h =[0] + [int(item) for item in input().split()]

dp = [0 for _ in range(N+1)]
dp[2]= abs(h[2] - h[1])


for i in range(3, N):
    for k in range(1,K+1):
        print(i,k, dp[i])
        if dp[i] != 0:
            if 2 <= i-k:
                dp[i] = min(dp[i], dp[i-k] + abs(h[i-k] - h[i]))
        else:
            print('make')
            if 2 <= i-k:
                dp[i] = dp[i-k] + abs(h[i-k] - h[i])

print(dp[1+N-K])

Fixed submission:
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])