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=A[0]
b=sum(B)
p=0
for i in range(N):
    count=a+b
    while count>K:
        count-=B[M-1]
        M-=1
    if i!=N-1:
        a+=A[i+1]
    p=max(p,i+M+1)
    if a>K:
        break
print(p)

from collections import deque
N,M,K=map(int,input().split())
A=deque(map(int,input().split()))
B=deque(map(int,input().split()))
if sum(A)+sum(B)<=K:
    print(len(A)+len(B))
else:
    ans=0
    count=0
    while count<K and len(A)!=0 and len(B)!=0:
        m=min(A[0],B[0])
        count+=m
        if m==A[0]:
            A.pop(0)
        else:
            B.pop(0)
        ans+=1
    if count<K and len(A)==0:
        while count<K:
            m=B[0]
            count+=m
            B.pop(0)
            ans+=1
    if count<K and len(B)==0:
        while count<K:
            m=A[0]
            count+=m
            A.pop(0)
            ans+=1
    if count>K:
        ans-=1
    print(ans)




    
















        


























            
    


    


    
    














    


    














from collections import deque
N,M,K=map(int,input().split())
A=deque(map(int,input().split()))
B=deque(map(int,input().split()))
if sum(A)+sum(B)<=K:
    print(len(A)+len(B))
else:
    ans=0
    count=0
    A.reverse()
    B.reverse()
    while count<K and len(A)!=0 and len(B)!=0:
        m=min(A[0],B[0])
        count+=m
        if m==A[0]:
            A.popleft()
        else:
            B.popleft()
        ans+=1
        if count>K:
            ans-=1
    if count<K and len(A)==0:
        while count<K:
            m=B[0]
            count+=m
            B.popleft()
            ans+=1
    if count<K and len(B)==0:
        while count<K:
            m=A[0]
            count+=m
            A.popleft()
            ans+=1
    print(ans)





    
















        


























            
    


    


    
    














    


    














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






    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted