Problem p02623 (python)

Fixed submission:
import numpy as np

N, M, K = list(map(int, input().split()))
A = list(map(int, [0] + input().split()))
B = list(map(int, [0] + input().split()))
cost = 0
cumsum_a = np.cumsum(A)
cumsum_b = np.cumsum(B)

num_book = 0
max_a = 0
ind_b = 0
max_b = 0
for i in range(1, N + 1):
    if cumsum_a[i] <= K:
        max_a = i
    else:
        break

for i in range(1, M + 1):
    if cumsum_b[i] <= K:
        max_b = i
    else:
        break

for i in range(max_a, -1, -1):
    for j in range(ind_b, max_b+1):
        if cumsum_b[j] + cumsum_a[i] <= K:
            # print("ok")
            num_book = max(i + j, num_book)
            ind_b = j
        else:
            break
print(num_book)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M, K = list(map(int, input().split()))
A = list(map(int, [0] + input().split()))
B = list(map(int, [0] + input().split()))
cost = 0
cumsum_a = np.cumsum(A)
cumsum_b = np.cumsum(B)

num_book = 0
dp = np.zeros((N + 2, M + 2)).astype(bool)

max_a = 0
ind_b = 0
max_b = 0
for i in range(1, N + 1):
    if cumsum_a[i] <= K:
        max_a = i
    else:
        break

for i in range(1, M + 1):
    if cumsum_b[i] <= K:
        max_b = i
    else:
        break

for i in range(max_a, -1, -1):
    for j in range(ind_b, max_b+1):
        if cumsum_b[j] + cumsum_a[i] <= K:
            # print("ok")
            num_book = max(i + j, num_book)
            ind_b = j
        else:
            break
print(num_book)

Buggy submission (verdict: Runtime Error):

ind_b = 0
max_b = 0
for i in range(1, N + 1):
    if cumsum_a[i] <= K:
        max_a = i
    else:
        break

for i in range(1, M + 1):
    if cumsum_b[i] <= K:
        max_b = i
    else:
        break

for i in range(max_a, -1, -1):
    for j in range(ind_b, max_b+1):
        if cumsum_b[j] + cumsum_a[i] <= K:
            # print("ok")
            num_book = max(i + j, num_book)
            ind_b = j
        else:
            break
print(num_book)

Buggy submission (verdict: Runtime Error):
import numpy as np
from queue import Queue

N, M, K = list(map(int, input().split()))
A = list(map(int, [0] + input().split()))
B = list(map(int, [0] + input().split()))
cost = 0
ind_a = 0
ind_b = 0
cumsum_a = np.cumsum(A)
cumsum_b = np.cumsum(B)
max_book = 1

queue = Queue()
queue.put([0, 0])
num_book = 0
dp = np.zeros((N + 2, M + 2)).astype(bool)

while not queue.empty():
    a, b = queue.get()
    if a + b + 1 <= num_book:
        continue
    if a + 1 <= N and b <= M:
        if cumsum_a[a + 1] + cumsum_b[b] <= K:
            if not dp[a + 1, b]:
                queue.put([a + 1, b])
                dp[a + 1, b] = True
            num_book = max(num_book, a + b + 1)
    if a <= N and b + 1 <= M:
        if cumsum_a[a] + cumsum_b[b + 1] <= K:
            if not dp[a, b + 1]:
                queue.put([a, b + 1])
                dp[a, b + 1] = True
            num_book = max(num_book, a + b + 1)

print(num_book)

# for i in range(max(N, M)):
#
#     # if ind_a < N and ind_b <= M:
#     #     dp[ind_a + 1, ind_b] = dp[ind_a, ind_b] + A[ind_a]
#     #     ind_a += 1
#     #     if dp[ind_a, ind_b] <= K and ind_a + ind_b > max_book:
#     #         max_book = ind_a + ind_b
#     #
#     # if ind_b < M and ind_a <= N:
#     #     dp[ind_a, ind_b + 1] = dp[ind_a, ind_b] + B[ind_b]
#     #     ind_b += 1
#     #     if dp[ind_a, ind_b] <= K and ind_a + ind_b > max_book:
#     #         max_book = ind_a + ind_b
#
#     if ind_a >= N and ind_b >= M:
#         break
#     elif ind_a < N and ind_b < M:

Buggy submission (verdict: Runtime Error):
import numpy as np
from queue import Queue

N, M, K = list(map(int, input().split()))
A = list(map(int, [0] + input().split()))
B = list(map(int, [0] + input().split()))
cost = 0
ind_a = 0
ind_b = 0
cumsum_a = np.cumsum(A)
cumsum_b = np.cumsum(B)
max_book = 1

queue = Queue()
queue.put([0, 0])
num_book = 0
dp = np.zeros((N + 1, M + 1)).astype(bool)
while not queue.empty():
    a, b = queue.get()
    if a + b + 1 <= num_book:
        continue
    if a + 1 <= N and b <= M:
        if cumsum_a[a + 1] + cumsum_b[b] <= K:
            if not dp[a+1, b]:
                queue.put([a + 1, b])
                dp[a+1, b] = True
            num_book = max(num_book, a + b + 1)
    if a <= N and b + 1 <= M:
        if cumsum_a[a] + cumsum_b[b + 1] <= K:
            if not dp[a, b+1]:
                queue.put([a, b + 1])
                dp[a , b+ 1] = True
            num_book = max(num_book, a + b + 1)

print(num_book)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M, K = list(map(int, input().split()))
A = list(map(int, [0] + input().split()))
B = list(map(int, [0] + input().split()))
cost = 0
ind_a = 0
ind_b = 0
dp = np.zeros((N + 3, M + 3)).astype(int)
cumsum_a = np.cumsum(A)
cumsum_b = np.cumsum(B)
max_book = 1
while True:
    for i in range(max_book + 1):
        if max_book - i <= N and i <= M:
            if K >= cumsum_a[max_book - i] + cumsum_b[i]:
                max_book += 1
                break
        else:
            continue
    else:
        break

print(max_book - 1)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cost = 0
ind_a = 0
ind_b = 0
max_book = 0
dp = np.zeros((N + 1, M + 1)).astype(int)
while True:
    if ind_a < N and ind_b <= M:
        dp[ind_a + 1, ind_b] = dp[ind_a, ind_b] + A[ind_a]
        ind_a += 1
        if dp[ind_a, ind_b] <= K and ind_a + ind_b > max_book:
            max_book = ind_a + ind_b
    if ind_b < M and ind_a <= N:
        dp[ind_a, ind_b + 1] = dp[ind_a, ind_b] + B[ind_b]
        ind_b += 1
        if dp[ind_a, ind_b] <= K and ind_a + ind_b > max_book:
            max_book = ind_a + ind_b

    if ind_a == N and ind_b == M:
        break
print(max_book)