from itertools import accumulate

from bisect import bisect_right



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

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

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



acc_a = list(accumulate(a))

acc_b = list(accumulate(b))



ans = 0

for i, e in enumerate(acc_b):

    if e > k:

        break

    a_cnt = bisect_right(acc_a, k - e)

    ans = max(ans, i + a_cnt)



print(ans)

from itertools import accumulate



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

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

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

INF = 10 ** 18



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

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

j = m

ans = 0

for i, e in enumerate(acc_a):

    while j >= 0 and acc_b[j] > k - acc_a[i]:

        j -= 1



    if j == -1:

        break



    ans = max(ans, i + j)



print(ans)

from itertools import accumulate
from bisect import bisect_right

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
acc_a = list(accumulate(a))
acc_b = list(accumulate(b))
ans = 0
for i, e in enumerate(acc_b):
    if e > k:
        break
    a_cnt = bisect_right(acc_a, k - e)
    ans = max(ans, i + a_cnt)
print(ans)

from itertools import accumulate

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
INF = 10**18
acc_a = [0] + list(accumulate(a))
acc_b = [0] + list(accumulate(b))
j = m
ans = 0
for i, e in enumerate(acc_a):
    while j >= 0 and acc_b[j] > k - acc_a[i]:
        j -= 1
    if j == -1:
        break
    ans = max(ans, i + j)
print(ans)

-from bisect import bisect_right -b = [0] + list(map(int, input().split())) -acc_a = list(accumulate(a)) -acc_b = list(accumulate(b)) +b = list(map(int, input().split())) +INF = 10**18 +acc_a = [0] + list(accumulate(a)) +acc_b = [0] + list(accumulate(b)) +j = m -for i, e in enumerate(acc_b): -    if e > k: +for i, e in enumerate(acc_a): +    while j >= 0 and acc_b[j] > k - acc_a[i]: +        j -= 1 +    if j == -1: -    a_cnt = bisect_right(acc_a, k - e) -    ans = max(ans, i + a_cnt) +    ans = max(ans, i + j)