Problem p03161 (python)

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 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])

Buggy 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])

Buggy 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])

Buggy 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])

Buggy 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])

Buggy 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])

Buggy 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])