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 = [*list(map(int, input().split()))]

B = [*list(map(int, input().split()))]

tot = sum(B)

ans, j = 0, m

for i in range(n+1):

    while j > 0 and tot > k:

        j -= 1

        tot -= B[j]

    if tot > k: break

    if i < n: tot += A[i]

    ans = max(ans, i+j)

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

-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) +A = [*list(map(int, input().split()))] +B = [*list(map(int, input().split()))] +tot = sum(B) -    if A[i] > k: +    while j > 0 and tot > k: +        j -= 1 +        tot -= B[j] +    if tot > k: -    while A[i] + B[j] > k: -        j -= 1 +    if i < n: +        tot += A[i]