Problem:
 Score : 300 points    Problem Statement 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.      Constraints  1 \leq N, M \leq 200000  1 \leq K \leq 10^9  1 \leq A_i, B_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  K  A_1  A_2  \ldots  A_N  B_1  B_2  \ldots  B_M       Output Print an integer representing the maximum number of books that can be read.        Sample Input 1 3 4 240
60 90 120
80 150 80 150      Sample Output 1 3  In this case, it takes us 60 , 90 , 120 minutes to read the 1 -st, 2 -nd, 3 -rd books from the top on Desk A, and 80 , 150 , 80 , 150 minutes to read the 1 -st, 2 -nd, 3 -rd, 4 -th books from the top on Desk B, respectively.  We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.   Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.  Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.  Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.        Sample Input 2 3 4 730
60 90 120
80 150 80 150      Sample Output 2 7       Sample Input 3 5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000      Sample Output 3 0  Watch out for integer overflows.

Solution (Python):
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 =0
j = M

for i in range(N+1):
    if a[i]>K:
        break
    
    while b[j]+a[i] > K :
        j -= 1
    ans = max(ans, i + j)

print(ans)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

suba=[0]
subb=[0]

for i in range(n):
    suba.append(a[i]+suba[i])
for j in range(m):
    subb.append(b[j]+subb[j])

ans=0
j=m
for i in range(n+1):
        
    if k<suba[i]:
        break

    while subb[j]>k-suba[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Solution (Python):
import bisect
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
K2 =K
count = 0
numa = 0
numb = 0
count2 = 0
for i in range(N+1):
    count += A[i]
    A[i] = count

B = [0]+list(map(int,input().split()))
count = 0
for i in range(M+1):
    count += B[i]
    B[i] = count


for i in range(N+1):
    K = K2
    if A[i] <= K:
        K -= A[i]
        if count2 < i + bisect.bisect_right(B, K):
            count2 = i + bisect.bisect_right(B, K)-1
    else:
        break
print(count2)

Solution (Python):
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)

Solution (Python):
import bisect


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ans = 0
    A_s = [0]
    B_s = [0]
    for a in A:
        A_s.append(A_s[-1]+a)
    tmp = 0
    for b in B:
        B_s.append(B_s[-1]+b)

    ans = 0
    for i in range(0, N+1):
        if A_s[i] > K:
            continue
        tmp = K - A_s[i]
        pos = bisect.bisect(B_s, tmp) - 1 + i
        if pos > ans:
            ans = pos
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N + 1):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M + 1:
        result = max(result, i + M)
    elif b[j] == t:
        result = max(result, i + j)
    else:
        result = max(result, i + j - 1)
print(result)

Solution (Python):
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
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])
j = 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)

Solution (Python):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

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

cnt, j = 0, m
for i, a_ in enumerate(A):
    d = k-a_
    t = 0
    if d < 0:
        break
    while d < B[j]:
        j-=1
    t = i+j
    cnt = max(cnt, t)
print(cnt)

Solution (Python):
n, m, k = list(map(int, input().split()))
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))

nss = [0]
for i, v in enumerate(ns):
    nss.append(nss[i] + ns[i])

mss = [0]
for i, v in enumerate(ms):
    mss.append(mss[i] + ms[i])

mx = 0
j = m
for i in range(n + 1):
    if nss[i] > k:
        break

    while mss[j] > k - nss[i]:
        j -= 1
    
    mx = max(mx, i + j)

print(mx)

Solution (Python):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
la, lb = [0], [0]
for i in range(n):
    la.append(la[i] + a[i])
for i in range(m):
    lb.append(lb[i] + b[i])
ans, j = 0, m
for i in range(n + 1):
    if la[i] > k:break
    while lb[j] > k - la[i]:j -= 1
    ans = max(ans, i + j)
print(ans)

Solution (Python):
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)

Solution (Python):
n,m,k = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = [0]*(n+1)
b = [0]*(m+1)
for i in range(n):
    a[i+1] = a[i] + A[i]
    
for i in range(m):
    b[i+1] = b[i] + B[i]

ans = 0
j = 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)

Solution (Python):
import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
j = M
for i in range(N+1):
    if AS[i] > K:
        break
    while j >= 0:
        if AS[i] + BS[j] <= K:
            if max < i + j:
                max = i + j
            break
        j -= 1

print(max)

Solution (Python):
import random
n, m, k = map(int, input().split())

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))




a_sum = [0]
b_sum = [0]
max_a = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] <= k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
j = m
for i in range(0, max_a+1):
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

Solution (Python):
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)

Solution (Python):
from bisect import bisect_right
n,m,k = map(int,input().split())

a =[int(x) for x in input().split()]
b = [int(x) for x in input().split()]

prefa = [0]
prefb =[0]

for i in range(n):
    prefa.append(prefa[-1] + a[i])
for j in range(m):
    prefb.append(prefb[-1] + b[j])
i,j = 1, 1
ans =0 

while i <= n:
    if prefa[i] > k:
        break 
    else:
        p = k - prefa[i] 
        aux = bisect_right(prefb , p)  - 1
        
        ans = max(ans, i + aux)
        i+=1 

while j <= m:
    if prefb[j] > k:
        break 
    else:
        p = k - prefb[j]
        aux = bisect_right(prefa , p) -1
        
        ans = max(ans, j + aux)
        j+=1
print(ans)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
from itertools import accumulate
ar=[0]+list(accumulate(a))
bru=[0]+list(accumulate(b))
from bisect import bisect_left as bl,bisect_right as br
ans=0

for i in range(n+1):
    g=ar[i]
    if g>k:break
    if k-g>=bru[-1]:ans=max(ans,i+m);continue
    j=br(bru,k-g)
    ans=max(ans,i+j-1)
    
print(ans)

Solution (Python):
n,m,k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

aa = [0]
bb = [0]

for i in range(n):
    aa.append(a[i] + aa[i])

for i in range(m):
    bb.append(b[i] + bb[i])

ans = 0
mstart = m
for i in range(n+1):
    if k - aa[i] < 0:
        break
    for j in range(mstart,-1,-1):
        if k - aa[i] - bb[j] >= 0:
            mstart = j
            break
    if ans < i + j :
        ans = i + j 

print(ans)

Solution (Python):
import random
n, m, k = map(int, input().split())

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))




a_sum = [0]
b_sum = [0]
max_a = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] <= k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
j = m
for i in range(0, max_a+1):
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

Solution (Python):
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)

Solution (Python):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for i in range(m):
    b_sum.append(b_sum[i] + b[i])
    
ans, j = 0, m
for i in range(n + 1):
    if a_sum[i] > k:
        break
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Solution (Python):
n, m, k = map(int, input().split())
lsta = list(map(int, input().split()))
lstb = list(map(int, input().split()))
a = [0]
b = [0]

for _ in range(n):
    a.append(lsta[_] + a[_])
    
for _ in range(m):
    b.append(lstb[_] + b[_])
    
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)

Solution (Python):
from sys import stdin
import sys

l = stdin.readline().rstrip().split(' ')
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = int(l[2])
n = int(l[0])
m = int(l[1])

sum = 0
a = [0]
for i in range(n):
    sum += A[i]
    a.append(sum)
sum = 0

b = [0]
for i in range(m):
    sum += B[i]
    b.append(sum)


ans = 0
j = 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)

Solution (Python):
(n,m,k),*A,=[list(map(int,i.split())) for i in open(0)]
a=A[0]
b=A[1]

aa=[0]
bb=[0]
for i in range(n):
    aa.append(aa[i]+a[i])
for i in range(m):
    bb.append(bb[i]+b[i])

ans=0

for i in range(n+1):
    if aa[i]>k:
        break
    while bb[m]>k-aa[i]:
        m-=1
    ans=max(ans,m+i)
        
print(ans)

Solution (Python):
def solve():
    a = [0]
    b = [0]
    for i in range(n):
        a.append(a[i]+deska[i])
    for j in range(m):
        b.append(b[j]+deskb[j])
    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)
    return ans

if __name__ == '__main__':
    n, m, k = map(int, input().split())
    deska = list(map(int, input().split()))
    deskb = list(map(int, input().split()))
    print(solve())

Solution (Python):
import bisect
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
bka=[0]*N
bkb=[0]*M
bka[0]=A[0]
bkb[0]=B[0]

for i in range(1,N):
    bka[i]+=bka[i-1]+A[i]
for j in range(1,M):
    bkb[j]+=bkb[j-1]+B[j]
ans=0
c=bisect.bisect_left(bkb,K)
if c != M:
    if bkb[c] == K:
        c +=+ 1
ans = max(ans, c)
for i in range(N):
    count=i+1
    k=K-bka[i]
    if k<0:continue
    c = bisect.bisect_left(bkb,k)
    b=c
    if c!=M:
        if bkb[c]==k:
            c+=count+1
        else:c+=count
    else:c+=count
    ans=max(ans,c)
print(ans)

Solution (Python):
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 = 0
j = 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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
from bisect import bisect_right
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=[0]*(n+1)
sb=[0]*(m+1)
for i in range(1,n+1):
    sa[i]=sa[i-1]+a[i-1]
for j in range(1,m+1):
    sb[j]=sb[j-1]+b[j-1]
ans=0
for x in range(n+1):
    if k-sa[x]>=0:
        k2=k-sa[x]
        l=bisect_right(sb,k2)-1
        if x+l>ans:
            ans=x+l
print(ans)

Solution (Python):

import sys
from itertools import accumulate
import numba
import numpy as np


def debug(*x):
    print(*x)


















@numba.njit
def solve(N, M, K, sA, sB):
    "void()"

    last_can_read = 0
    last_max_j = M
    for i in range(N + 1):
        j = last_max_j
        while j >= 0:
            if sA[i] + sB[j] <= K:
                if last_can_read < i + j:
                    last_can_read = i + j
                last_max_j = j
                break
            j -= 1

    print(last_can_read)


def main():
    N, M, K = map(int, input().split())

    AS = list(map(int, input().split()))
    BS = list(map(int, input().split()))

    sA = np.array([0] + list(accumulate(AS)))
    sB = np.array([0] + list(accumulate(BS)))
    
    solve(N, M, K, sA, sB)


T1 = '''
3 4 240
60 90 120
80 150 80 150
'''

T2 = '''
3 4 730
60 90 120
80 150 80 150
'''


def _test():
    """
    >>> as_input(T1)
    >>> main()
    3
    >>> as_input(T2)
    >>> main()

    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        
        
        from my_module import solve  
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()

Solution (Python):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
a_list = [0]
b_list = [0]
for i in range(n):
    a_list.append(a[i] + a_list[i])
for i in range(m):
    b_list.append(b[i] + b_list[i])

ans = 0
num = m
for i in range(n+1):
    if a_list[i] > k:
        break
    while b_list[num] > k - a_list[i]:
        num -= 1
    ans = max(ans,i + num)
print(ans)

Solution (Python):
import bisect
n,m,k = map(int,input().split())
a_list = [0]+list(map(int,input().split()))
b_list = list(map(int,input().split()))
b_added = [0]
for b_i in b_list:
    b_added.append(b_added[-1]+b_i)
    if b_added[-1]>k:
        break
    
max_book = 0
temp_ki = 0
break_flag = False
for i in range(len(a_list)):
    temp_ki += a_list[i]
    if temp_ki > k:
        if i-1>max_book:
            max_book = i-1
        break_flag = True
        break
    temp_j = bisect.bisect(b_added,k-temp_ki)-1
    if i+temp_j > max_book:
        max_book = i+temp_j
        
print(max_book)

Solution (Python):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]

for i in range(N):
    a.append(a[i] + A[i])

for j in range(M):
    b.append(b[j] + B[j])

ans = 0
j = M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(i + j, ans)

print(ans)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

sa=[0]
sum=0
for i in range(n):
    sum+=a[i]
    sa.append(sum)
sb=[0]
sum=0
for i in range(m):
    sum+=b[i]
    sb.append(sum)

ans=0
j=m
for i in range(n+1):
    if k<sa[i]:
        break
    while sb[j]>k-sa[i]:
        j-=1
    ans=max(ans,i+j)

print(ans)

Solution (Python):
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

asum = [0]
for i in range(len(a)):
	if asum[i]+a[i]<=k:
		asum.append(asum[i]+a[i])
	else:
		break

bsum = [0]
for i in range(len(b)):
	if bsum[i]+b[i]<=k:
		bsum.append(bsum[i]+b[i])
	else:
		break

ans = 0
for i in range(len(asum)):
	kb = k-asum[i]
	while len(bsum)>0 and bsum[-1]>kb:
		bsum.pop()
	ans = max(ans, len(bsum)+i-1)

print(ans)

Solution (Python):
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 a[i] + b[j] > K:
        j -= 1
    ans = max(ans, i+j)
    
print(ans)

Solution (Python):
n, m, k = map(int,input().split())
a = [0] + list(map(int,input().split()))
b = [0] + list(map(int,input().split()))

for i in range(1, n+1):
    a[i] += a[i-1]
    
for j in range(1, m+1):
    b[j] += b[j-1]
    
ans = 0
bc = m

for ac in range(n+1):
    if a[ac] > k:
        continue
    
    while a[ac] + b[bc] > k:
        bc -= 1
        
    ans  = max(ans, ac+bc)

print(ans)

Solution (Python):
import sys
from itertools import accumulate

n,m,k=map(int, input().split())
a = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
b = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
ans = 0
j = m



for i,item in enumerate(a):
        if k<item:
            break
        while k<item+b[j]:
            j -= 1
        ans = max(ans,i+j)

print(ans)

Solution (Python):
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)

Solution (Python):
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

rui_A = [0 for _ in range(N)]
rui_B = [0 for _ in range(M)]



rui_A[0] = A[0]
for i in range(N-1):
    rui_A[i+1] = rui_A[i] + A[i+1]

rui_B[0] = B[0]
for i in range(M-1):
    rui_B[i+1] = rui_B[i] + B[i+1]

rui_A.insert(0,0)

max_book = 0
for i in range(len(rui_A)):
    nokori = K - rui_A[i]
    if nokori >= 0:
        B_posi = bisect.bisect_right(rui_B,nokori)
        if max_book < B_posi + i:
            max_book = B_posi + i
print(max_book)

Solution (Python):
n,m,k = map(int, input().split())

from collections import deque

an = list(map(int, input().split()))

bn = list(map(int, input().split()))

accum_a = [0]
accum_b = [0]


for a_i in range(0,len(an)):

    sumCandidate = accum_a[-1] + an[a_i]
    if sumCandidate > k:
        break
    accum_a.append(sumCandidate)

for b_i in range(0,len(bn)):
    i_ = accum_b[-1] + bn[b_i]
    if i_ > k:
        break
    accum_b.append(i_)

j = len(accum_b) - 1
ans = 0
for i in range(len(accum_a)):

    if accum_a[i] > k:
        break

    while accum_b[j] > k - accum_a[i]:
        j -= 1

    ans = max(ans, i+j)
print(ans)

Solution (Python):
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A2 = [0] * (N + 1)
for i in range(1, N + 1):
  A2[i] = A2[i - 1] + A[i - 1]

B2 = [0] * (M + 1)
for i in range(1, M + 1):
  B2[i] = B2[i - 1] + B[i - 1]



ans = 0
for i in range(N + 1):
  time = K - A2[i]
  if time < 0:
    print(ans)
    quit()
  else:
    index = bisect.bisect_right(B2, time) - 1
    
    ans = max(ans, i + index)
    
print(ans)

Solution (Python):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a_s = [0] * (len(A)+1)
b_s = [0] * (len(B)+1)
for i in range(len(A)):
    a_s[i+1] = a_s[i] + A[i]
for i in range(len(B)):
    b_s[i + 1] = b_s[i] + B[i]

ans = 0
j = M
for i in range(len(a_s)):
    if a_s[i] > K:
        break
    while b_s[j] + a_s[i] > K:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Solution (Python):
na,nb,k = map(int, input().split())
ta = list(map(int, input().split()))
tb = list(map(int, input().split()))

a = [0]
for i in range(na):
  a.append( a[i] + ta[i] )
b = [0]
for i in range(nb):
  b.append( b[i] + tb[i] )

ans, j=0, nb
for i in range(na + 1):
  if a[i] > k:
    break
  while True:
    if a[i] + b[j] > k:
      j -= 1
    else:
      break
  ans = max(ans, i+j)
    
print(ans)

Solution (Python):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


A_sum, B_sum = [0], [0]
for i, a in enumerate(A):
    A_sum.append(A_sum[i] + a)
for i, b in enumerate(B):
    B_sum.append(B_sum[i] + b)

ans = 0
j = M





for i in range(N+1):
    if A_sum[i] > K:
        break
    while B_sum[j] > K - A_sum[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Solution (Python):
from bisect import bisect

N, M, K = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = list(map(int, input().split()))
R_B = [0]*(M+1)
i = 0
while i < M:
  R_B[i+1] = R_B[i]+B[i]
  i += 1 
ans = 0
i = 0
while i <= N and K >= A[i]:
  K -= A[i]
  idx = bisect(R_B, K)
  ans = max(ans, i+idx-1)
  i += 1
print(ans)

Solution (Python):

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
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])
for i in range(n+1):
    if a[i] > k:
        break
    while b[m] > k - a[i]:
        m -= 1
    ans = max(ans, i + m)
print(ans)

Solution (Python):
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sa = [0]*(n+1)
sb = [0]*(m+1)
for i in range(n):
    sa[i+1] = sa[i]+a[i]
for i in range(m):
    sb[i+1] = sb[i]+b[i]
ans = 0
for i in range(n+1):
    t = sa[i]
    s = i
    tl = k-t
    if tl < 0:
        continue
    s += bisect.bisect_right(sb, tl)-1
    ans = max(ans,s)
print(ans)

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

Solution (Python):
n,m,k = list(map(int,input().split()))

a = list(map(int,input().split()))
b = list(map(int,input().split()))

asum = [0]
bsum = [0]

for i in range(n):
    asum.append(asum[i] + a[i])
for i in range(m):
    bsum.append(bsum[i] + b[i])

best = m
answer = 0
for i in range(n+1):
    j = best
    while 1:
        if bsum[j] <= (k - asum[i]):
            best = j
            if answer < i + j:
                answer = i + j
            break
        j -= 1
        if j < 0:
            break

print(answer)

Solution (Python):
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)

Solution (Python):
from itertools import accumulate

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0

A = list(accumulate(A))
A.insert(0,0)
B = list(accumulate(B))
B.insert(0,0)

j = 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)

Solution (Python):
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)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

from itertools import accumulate
aa=[0]+list(accumulate(a))
bb=[0]+list(accumulate(b))

from bisect import bisect_left,bisect

kmax=0
for i in range(n+1):
    if k<aa[i]:
        break
    kk=k-aa[i]
    k2=bisect(bb,kk)-1

    kmax=max(kmax,k2+i)

print(kmax)

Solution (Python):
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)

Solution (Python):
import numpy

n,m,k = map(int,input().split())
li_a = list(map(int,input().split()))
li_b = list(map(int,input().split()))

li_A = [0] + list(numpy.cumsum(li_a))
li_B = [0] + list(numpy.cumsum(li_b))

ans, j = 0,m
for i in range(n+1):
    if li_A[i] > k:
        break
    while li_B[j] + li_A[i]> k:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Solution (Python):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumA, sumB = [0], [0]
sa, sb = 0, 0
for a in A:
    sa += a
    sumA.append(sa)
for b in B:
    sb += b
    sumB.append(sb)


n_max = 0
nb_max = M
for na in range(0, N+1):
    for nb in range(nb_max, -1, -1):
        k = sumA[na] + sumB[nb]
        if k <= K:
            n = na + nb
            n_max = max(n_max, n)
            nb_max = nb
            break
print(n_max)

Solution (Python):
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])

len_B = M+1
res = []
for i, a_ in enumerate(a):
    for j in range(len_B)[::-1]:
        
        if a_ + b[j] <= K:
            res.append(i+j)
            break
    len_B = j+1

print(0 if len(res) < 1 else max(res))

Solution (Python):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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 = 0
j = 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)

Solution (Python):
import sys
from itertools import accumulate

def Main():
    n,m,k = map(int,sys.stdin.readline().rstrip().split())
    a = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
    b = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))

    ans = 0
    j = m
    for i,item in enumerate(a):
        if k<item:  break
        while k<item+b[j]:
            j -= 1
        ans = max(ans,i+j)
    print(ans)
    return

if __name__=='__main__':
    Main()

Solution (Python):
import bisect

N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
for i in range(N):
    a += [a[i] + A[i]]
for i in range(M):
    b += [b[i] + B[i]]

ans = 0
for i in range(N+1):
    if a[i] <= K:
        ans = max(ans, i + bisect.bisect_right(b, K - a[i])-1)

print(ans)

Solution (Python):
import sys
from itertools import accumulate

def Main():
    n,m,k = map(int,sys.stdin.readline().rstrip().split())
    a = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
    b = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))

    ans = 0
    j = m
    for i,item in enumerate(a):
        if k<item:  break
        while k<item+b[j]:
            j -= 1
        ans = max(ans,i+j)
    print(ans)
    return

if __name__=='__main__':
    Main()