from itertools import accumulate

import bisect

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

Acum = [0]+list(accumulate(list(map(int, input().split()))))

Bcum = [0]+list(accumulate(list(map(int, input().split()))))



ans = 0

for a in range(n+1):

    if k-Acum[a] < 0:

        break

    b = bisect.bisect_right(Bcum, k-Acum[a])-1

    if ans < a+b:

        ans = a+b

print(ans)

from itertools import accumulate

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

Acum = [0]+list(accumulate(list(map(int, input().split()))))

Bcum = [0]+list(accumulate(list(map(int, input().split()))))



ans = 0

b = m

for a in range(n+1):

    if k < Acum[a]:

        break

    while k < Acum[a]+Bcum[b]:

        b -= 1

    if ans < a+b:

        ans = a+b

print(ans)

from itertools import accumulate
import bisect

n, m, k = list(map(int, input().split()))
Acum = [0] + list(accumulate(list(map(int, input().split()))))
Bcum = [0] + list(accumulate(list(map(int, input().split()))))
ans = 0
for a in range(n + 1):
    if k - Acum[a] < 0:
        break
    b = bisect.bisect_right(Bcum, k - Acum[a]) - 1
    if ans < a + b:
        ans = a + b
print(ans)

from itertools import accumulate

n, m, k = list(map(int, input().split()))
Acum = [0] + list(accumulate(list(map(int, input().split()))))
Bcum = [0] + list(accumulate(list(map(int, input().split()))))
ans = 0
b = m
for a in range(n + 1):
    if k < Acum[a]:
        break
    while k < Acum[a] + Bcum[b]:
        b -= 1
    if ans < a + b:
        ans = a + b
print(ans)

-import bisect +b = m -    if k - Acum[a] < 0: +    if k < Acum[a]: -    b = bisect.bisect_right(Bcum, k - Acum[a]) - 1 +    while k < Acum[a] + Bcum[b]: +        b -= 1