Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)

N,M,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
j = 0
time = 0
count = 0
buff = -1
while time < K and count-buff == 1 and i < N or j < M:
    buff = count
    if i >= N or j >= M:
        if i >= N:
            if K-time>B[j]:
                time += B[j]
                j += 1
                count += 1
        elif j >= M:
            if K-time>A[i]:
                time += A[i]
                i += 1
                count += 1
    else:
        if A[i] < B[j]:
            if K-time>A[i]:
                time += A[i]
                i += 1
                count += 1
        elif A[i] >= B[j]:
            if K-time>B[j]:
                time += B[j]
                j += 1
                count += 1

print(count)

N,M,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
j = 0
time = 0
count = 0
buff = 0
while time < K and count-buff ==1 and i < N or j < M:
    buff = count
    if i >= N or j >= M:
        if i >= N:
            time += B[j]
            j += 1
            count += 1
        elif j >= M:
            time += A[i]
            i += 1
            count += 1
    else:
        if A[i] < B[j]:
            time += A[i]
            i += 1
            count += 1
        elif A[i] >= B[j]:
            time += B[j]
            j += 1
            count += 1

print(count)

N,M,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
j = 0
time = 0
count = 0
buff = -1
while time < K and count-buff == 1 and i < N or j < M:
    buff = count
    if i >= N or j >= M:
        if i >= N:
            time += B[j]
            j += 1
            count += 1
        elif j >= M:
            time += A[i]
            i += 1
            count += 1
    else:
        if A[i] < B[j]:
            time += A[i]
            i += 1
            count += 1
        elif A[i] >= B[j]:
            time += B[j]
            j += 1
            count += 1

print(count)

N,M,K = (int(x) for x in input().split())
A = list(map(int, input.split()))
B = list(map(int, input.split()))
i,j = 0
time = 0
while time < K and i < N-1 or j < M-1:
    if A[i] < B[j]:
        time += A[i]
        i += 1
    elif A[i] > B[j]:
        time += B[j]
        j += 1
allbooks = i + j
print(allbooks)

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted