from itertools import accumulate

import bisect

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

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

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

i = 0

j = 0

total = 0



ac = list(accumulate(a))

bc = list(accumulate(b))



ans = 0

for i in range(bisect.bisect(ac, k)):

    bi = bisect.bisect(bc, k - ac[i])

    ans = max(ans, i+1+bi)

for i in range(bisect.bisect(bc, k)):

    bi = bisect.bisect(ac, k - bc[i])

    ans = max(ans, i+1+bi)

ans = max(ans, bisect.bisect(ac, k))

ans = max(ans, bisect.bisect(bc, k))

print(ans)
from itertools import accumulate

import bisect

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

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

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

ac = [0] + list(accumulate(a))

bc = [0] + list(accumulate(b))



ans = 0

for i in range(bisect.bisect(ac, k)):

    bi = bisect.bisect(bc, k - ac[i])

    ans = max(ans, i+bi-1)

print(ans)
from itertools import accumulate
import bisect

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
j = 0
total = 0
ac = list(accumulate(a))
bc = list(accumulate(b))
ans = 0
for i in range(bisect.bisect(ac, k)):
    bi = bisect.bisect(bc, k - ac[i])
    ans = max(ans, i + 1 + bi)
for i in range(bisect.bisect(bc, k)):
    bi = bisect.bisect(ac, k - bc[i])
    ans = max(ans, i + 1 + bi)
ans = max(ans, bisect.bisect(ac, k))
ans = max(ans, bisect.bisect(bc, k))
print(ans)

from itertools import accumulate
import bisect

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ac = [0] + list(accumulate(a))
bc = [0] + list(accumulate(b))
ans = 0
for i in range(bisect.bisect(ac, k)):
    bi = bisect.bisect(bc, k - ac[i])
    ans = max(ans, i + bi - 1)
print(ans)

-i = 0 -j = 0 -total = 0 -ac = list(accumulate(a)) -bc = list(accumulate(b)) +ac = [0] + list(accumulate(a)) +bc = [0] + list(accumulate(b)) -    ans = max(ans, i + 1 + bi) -for i in range(bisect.bisect(bc, k)): -    bi = bisect.bisect(ac, k - bc[i]) -    ans = max(ans, i + 1 + bi) -ans = max(ans, bisect.bisect(ac, k)) -ans = max(ans, bisect.bisect(bc, k)) +    ans = max(ans, i + bi - 1)