from itertools import accumulate

from bisect import bisect_right



N, M, K = list(map(int, input().split()))

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

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



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

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



ans = 0

for i in range(N + 1):

    if a[i] > K:

        break

    j = bisect_right(b, K - a[i]) - 1

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



A_cumu = [0] + list(accumulate(A))

B_cumu = [0] + list(accumulate(B))



curr_max = 0

for i in range(N + 1):

    curr = A_cumu[i]

    if curr > K:

        break

    j = bisect_right(B_cumu, K - curr) - 1

    curr_max = max(curr_max, i + j)



print(curr_max)

from itertools import accumulate
from bisect import bisect_right

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))
ans = 0
for i in range(N + 1):
    if a[i] > K:
        break
    j = bisect_right(b, K - a[i]) - 1
    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 = list(map(int, input().split()))
A_cumu = [0] + list(accumulate(A))
B_cumu = [0] + list(accumulate(B))
curr_max = 0
for i in range(N + 1):
    curr = A_cumu[i]
    if curr > K:
        break
    j = bisect_right(B_cumu, K - curr) - 1
    curr_max = max(curr_max, i + j)
print(curr_max)

-a = [0] + list(accumulate(A)) -b = [0] + list(accumulate(B)) -ans = 0 +A_cumu = [0] + list(accumulate(A)) +B_cumu = [0] + list(accumulate(B)) +curr_max = 0 -    if a[i] > K: +    curr = A_cumu[i] +    if curr > K: -    j = bisect_right(b, K - a[i]) - 1 -    ans = max(ans, i + j) -print(ans) +    j = bisect_right(B_cumu, K - curr) - 1 +    curr_max = max(curr_max, i + j) +print(curr_max)