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

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

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

SA, SB = [0], [0]

for i in range(n):

    SA.append(SA[i] + A[i])

for j in range(m):

    SB.append(SB[j] + B[j])

ans, tmp = 0, m

for i in range(n + 1):

    if SA[i] > k:

        break

    for j in range(tmp + 1)[::-1]:

        if SA[i] + SB[j] <= k:

            break

    ans = max(ans, i + j)

    tmp = j

print(ans)

import bisect

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

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

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

SA, SB = [0], [0]

for i in range(n):

    SA.append(SA[i] + A[i])

for j in range(m):

    SB.append(SB[j] + B[j])

ans = 0

for i in range(n + 1):

    if SA[i] <= k:

        j = bisect.bisect_right(SB, k - SA[i]) - 1

        ans = max(ans, i + j)

print(ans)

n, m, k = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
(*B,) = list(map(int, input().split()))
SA, SB = [0], [0]
for i in range(n):
    SA.append(SA[i] + A[i])
for j in range(m):
    SB.append(SB[j] + B[j])
ans, tmp = 0, m
for i in range(n + 1):
    if SA[i] > k:
        break
    for j in range(tmp + 1)[::-1]:
        if SA[i] + SB[j] <= k:
            break
    ans = max(ans, i + j)
    tmp = j
print(ans)

import bisect

n, m, k = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
(*B,) = list(map(int, input().split()))
SA, SB = [0], [0]
for i in range(n):
    SA.append(SA[i] + A[i])
for j in range(m):
    SB.append(SB[j] + B[j])
ans = 0
for i in range(n + 1):
    if SA[i] <= k:
        j = bisect.bisect_right(SB, k - SA[i]) - 1
        ans = max(ans, i + j)
print(ans)

+import bisect + -ans, tmp = 0, m +ans = 0 -    if SA[i] > k: -        break -    for j in range(tmp + 1)[::-1]: -        if SA[i] + SB[j] <= k: -            break -    ans = max(ans, i + j) -    tmp = j +    if SA[i] <= k: +        j = bisect.bisect_right(SB, k - SA[i]) - 1 +        ans = max(ans, i + j)