from bisect import bisect

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

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

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

a = [0] * (N+1)

b = [0] * (M+1)

for i in range(N):

    a[i+1] = a[i] + A[i]

for i in range(M):

    b[i+1] = b[i] + B[i]

ans = 0

for i in range(N+1):

    tmp = K - a[i]

    if tmp < 0:

        break

    ans = max(ans, i + bisect(b, tmp) - 1)

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

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

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

a = [0] * (N+1)

b = [0] * (M+1)

for i in range(N):

    a[i+1] = a[i] + A[i]

for i in range(M):

    b[i+1] = b[i] + B[i]

ans = 0

j = M

for i in range(N+1):

    if a[i] > K:

        break

    while b[j] > K - a[i]:

        j -= 1

    ans = max(ans, i + j)

print(ans)
from bisect import bisect

N, M, K = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
(*B,) = list(map(int, input().split()))
a = [0] * (N + 1)
b = [0] * (M + 1)
for i in range(N):
    a[i + 1] = a[i] + A[i]
for i in range(M):
    b[i + 1] = b[i] + B[i]
ans = 0
for i in range(N + 1):
    tmp = K - a[i]
    if tmp < 0:
        break
    ans = max(ans, i + bisect(b, tmp) - 1)
print(ans)

N, M, K = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
(*B,) = list(map(int, input().split()))
a = [0] * (N + 1)
b = [0] * (M + 1)
for i in range(N):
    a[i + 1] = a[i] + A[i]
for i in range(M):
    b[i + 1] = b[i] + B[i]
ans = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

-from bisect import bisect - +j = M -    tmp = K - a[i] -    if tmp < 0: +    if a[i] > K: -    ans = max(ans, i + bisect(b, tmp) - 1) +    while b[j] > K - a[i]: +        j -= 1 +    ans = max(ans, i + j)