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

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

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

for i in range(1,n):

    a[i] += a[i-1]

for i in range(1,m):

    b[i] += b[i-1]

a = [0]+a

b = [0]+b



ans = 0

ALL = 0

j = m



for i in range(n+1):

    if a[i] > k:

        continue

    else:

        while k-a[i] < b[j] :

            j -=1

    ans = max(ans,i+j)

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

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

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



from itertools import accumulate



A = list(accumulate(A))

B = list(accumulate(B))

A = [0] + A

B = [0] + B



ans = 0

num = b

for i in range(a+1):

    if A[i] > k:

        continue

    while True :

        if A[i] + B[num] > k:

            num -=1

        else:

            ans = max(ans,i+num)

            break

print(ans)
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(1, n):
    a[i] += a[i - 1]
for i in range(1, m):
    b[i] += b[i - 1]
a = [0] + a
b = [0] + b
ans = 0
ALL = 0
j = m
for i in range(n + 1):
    if a[i] > k:
        continue
    else:
        while k - a[i] < b[j]:
            j -= 1
    ans = max(ans, i + j)
print(ans)

a, b, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
from itertools import accumulate

A = list(accumulate(A))
B = list(accumulate(B))
A = [0] + A
B = [0] + B
ans = 0
num = b
for i in range(a + 1):
    if A[i] > k:
        continue
    while True:
        if A[i] + B[num] > k:
            num -= 1
        else:
            ans = max(ans, i + num)
            break
print(ans)

-n, m, k = list(map(int, input().split())) -a = list(map(int, input().split())) -b = list(map(int, input().split())) -for i in range(1, n): -    a[i] += a[i - 1] -for i in range(1, m): -    b[i] += b[i - 1] -a = [0] + a -b = [0] + b +a, b, k = list(map(int, input().split())) +A = list(map(int, input().split())) +B = list(map(int, input().split())) +from itertools import accumulate + +A = list(accumulate(A)) +B = list(accumulate(B)) +A = [0] + A +B = [0] + B -ALL = 0 -j = m -for i in range(n + 1): -    if a[i] > k: +num = b +for i in range(a + 1): +    if A[i] > k: -    else: -        while k - a[i] < b[j]: -            j -= 1 -    ans = max(ans, i + j) +    while True: +        if A[i] + B[num] > k: +            num -= 1 +        else: +            ans = max(ans, i + num) +            break