from sys import stdin

from bisect import bisect

input = stdin.readline



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

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

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



for i in range(1, N):

    A[i] += A[i - 1]



for i in range(1, M):

    B[i] += B[i - 1]



ans = 0



for i, a in enumerate(A):

    time = K - a

    if time < 0:

        break

    cnt = i + 1

    if time != 0:

        tmp = bisect(B, time)

        cnt += tmp

    ans = max(ans, cnt)



for i, b in enumerate(B):

    time = K - b

    if time < 0:

        break

    cnt = i + 1

    if time != 0:

        tmp = bisect(A, time)

        cnt += tmp

    ans = max(ans, cnt)



print(ans)

from sys import stdin

input = stdin.readline



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

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

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



sumA = [0]

sumB = [0]





for i in range(N):

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



for i in range(M):

    sumB.append(sumB[i] + B[i])



ans = 0

t = M



for i in range(N + 1):

    for j in range(t, -1, -1):

        if K < sumA[i] + sumB[j]:

            t -= 1

            continue

        else:

            ans = max(ans, i + j)

            break



print(ans)

from sys import stdin
from bisect import bisect

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

from sys import stdin

input = stdin.readline
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sumA = [0]
sumB = [0]
for i in range(N):
    sumA.append(sumA[i] + A[i])
for i in range(M):
    sumB.append(sumB[i] + B[i])
ans = 0
t = M
for i in range(N + 1):
    for j in range(t, -1, -1):
        if K < sumA[i] + sumB[j]:
            t -= 1
            continue
        else:
            ans = max(ans, i + j)
            break
print(ans)

-from bisect import bisect -for i in range(1, N): -    A[i] += A[i - 1] -for i in range(1, M): -    B[i] += B[i - 1] +sumA = [0] +sumB = [0] +for i in range(N): +    sumA.append(sumA[i] + A[i]) +for i in range(M): +    sumB.append(sumB[i] + B[i]) -for i, a in enumerate(A): -    time = K - a -    if time < 0: -        break -    cnt = i + 1 -    if time != 0: -        tmp = bisect(B, time) -        cnt += tmp -    ans = max(ans, cnt) -for i, b in enumerate(B): -    time = K - b -    if time < 0: -        break -    cnt = i + 1 -    if time != 0: -        tmp = bisect(A, time) -        cnt += tmp -    ans = max(ans, cnt) +t = M +for i in range(N + 1): +    for j in range(t, -1, -1): +        if K < sumA[i] + sumB[j]: +            t -= 1 +            continue +        else: +            ans = max(ans, i + j) +            break