from bisect import *

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

A = [0]

for x in map(int, input().split()):

    x += A[-1]

    if x > k: break

    A.append(x)

B = [0]

for x in map(int, input().split()):

    x += B[-1]

    if x > k: break

    B.append(x)

ans = 0

for i in range(len(A)):

    ans = max(ans, i + (bisect_right(B, k-A[i]) - 1))

print(ans)

from bisect import *

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

A, B = [0], [0]

for x in map(int, input().split()): A.append(A[-1]+x)

for x in map(int, input().split()): B.append(B[-1]+x)

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)

from bisect import *

n, m, k = list(map(int, input().split()))
A = [0]
for x in map(int, input().split()):
    x += A[-1]
    if x > k:
        break
    A.append(x)
B = [0]
for x in map(int, input().split()):
    x += B[-1]
    if x > k:
        break
    B.append(x)
ans = 0
for i in range(len(A)):
    ans = max(ans, i + (bisect_right(B, k - A[i]) - 1))
print(ans)

from bisect import *

n, m, k = list(map(int, input().split()))
A, B = [0], [0]
for x in map(int, input().split()):
    A.append(A[-1] + x)
for x in map(int, input().split()):
    B.append(B[-1] + x)
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)

-A = [0] +A, B = [0], [0] -    x += A[-1] -    if x > k: +    A.append(A[-1] + x) +for x in map(int, input().split()): +    B.append(B[-1] + x) +ans, j = 0, m +for i in range(n + 1): +    if A[i] > k: -    A.append(x) -B = [0] -for x in map(int, input().split()): -    x += B[-1] -    if x > k: -        break -    B.append(x) -ans = 0 -for i in range(len(A)): -    ans = max(ans, i + (bisect_right(B, k - A[i]) - 1)) +    while A[i] + B[j] > k: +        j -= 1 +    ans = max(ans, i + j)