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):
# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 
count_time = 0 

if K<A[0] and K<B[0]:
    print(count)
 
else:
    while K >= count_time:
        if len(A)!=0 and len(B)!=0:
            if A[0] >= B[0]:
                count_time += B[0]
                count += 1
                B.pop(0)
                print(count_time)
                continue

            elif A[0] < B[0]:
                count += 1
                count_time += A[0]
                A.pop(0)
                print(count_time)
                continue

        elif len(A)==0 and len(B)!=0:
            count += 1
            count_time += B[0]
            B.pop(0)
            print(count_time)
            continue

        elif len(B)==0 and len(A)!=0:
            count += 1
            count_time += A[0]
            A.pop(0)
            print(count_time)
            continue

        else:
            count += 1
            print(count_time)
            break
        
    print(count-1)


# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 
count_time = 0 

if K<A[0] or K<B[0]:
    pass
 
else:
    while K > count_time:
        if len(A)!=0 and len(B)!=0:
            if A[0] >= B[0]:
                count_time += B[0]
                count += 1
                B.pop(0)

            if A[0] < B[0]:
                count += 1
                count_time += A[0]
                A.pop(0)

        elif len(A)==0 and len(B)!=0:
            count += 1
            count_time += B[0]
            B.pop(0)

        elif len(B)==0 and len(A)!=0:
            count += 1
            count_time += A[0]
            A.pop(0)

        else:
            count += 1
            break

print(count)


# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 
count_time = 0 
a = [0]
b = [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)
 


# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 
count_time = 0 
a = [0]
b = [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: Wrong Answer

Runtime Error

Runtime Error

Accepted