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()))



x = [0] * (N + 1)

for i in range(N):

    x[i + 1] = x[i] + A[i]

    

y = [0] * (M + 1)

for i in range(M):

    y[i + 1] = y[i] + B[i]



ans = 0

for i in range(N + 1):

    res = K - x[i]

    if res > 0:

        j = bisect_right(y, res)

        j -= 1

    elif res == 0:

        j = 0

    else:

        continue



    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()))



x = [0] * (N + 1)

y = [0] * (M + 1)

for i in range(N):

    x[i + 1] = x[i] + A[i]



for i in range(M):

    y[i + 1] = y[i] + B[i]



j = M

ans = 0

for i in range(N + 1):

    if x[i] > K:

        continue

    while j >= 0 and x[i] + y[j] > K:

        j -= 1

    ans = max(ans, i + j)

print(ans)

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()))
x = [0] * (N + 1)
for i in range(N):
    x[i + 1] = x[i] + A[i]
y = [0] * (M + 1)
for i in range(M):
    y[i + 1] = y[i] + B[i]
ans = 0
for i in range(N + 1):
    res = K - x[i]
    if res > 0:
        j = bisect_right(y, res)
        j -= 1
    elif res == 0:
        j = 0
    else:
        continue
    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()))
x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
    x[i + 1] = x[i] + A[i]
for i in range(M):
    y[i + 1] = y[i] + B[i]
j = M
ans = 0
for i in range(N + 1):
    if x[i] > K:
        continue
    while j >= 0 and x[i] + y[j] > K:
        j -= 1
    ans = max(ans, i + j)
print(ans)

-from bisect import bisect_right - +y = [0] * (M + 1) -y = [0] * (M + 1) +j = M -    res = K - x[i] -    if res > 0: -        j = bisect_right(y, res) +    if x[i] > K: +        continue +    while j >= 0 and x[i] + y[j] > K: -    elif res == 0: -        j = 0 -    else: -        continue