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

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

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



MAX = 10 ** 18



# 累積和

accA, accB = [0] * (n + 1), [0] * (m + 1)

accA[1], accB[1] = A[0], B[0]

for i in range(2, n + 1):

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

for i in range(2, m + 1):

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

accA.append(MAX)

accB.append(MAX)



from bisect import bisect_left, bisect_right



res = 0

for i in range(n + 1):

    tmp = accA[i]

    idx = bisect_right(accB, k - tmp) - 1

    if tmp + accB[idx] <= k:

        res = max(res, i + idx)

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

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

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



t = sum(B)



# しゃくとり法

res = 0

j = m

for i in range(n + 1):

    while j > 0 and t > k:

        j -= 1

        t -= B[j]

    if t > k:

        break

    res = max(res, i + j)

    if i == n: break

    t += A[i]



print(res)
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
MAX = 10**18
# 累積和
accA, accB = [0] * (n + 1), [0] * (m + 1)
accA[1], accB[1] = A[0], B[0]
for i in range(2, n + 1):
    accA[i] = accA[i - 1] + A[i - 1]
for i in range(2, m + 1):
    accB[i] = accB[i - 1] + B[i - 1]
accA.append(MAX)
accB.append(MAX)
from bisect import bisect_left, bisect_right

res = 0
for i in range(n + 1):
    tmp = accA[i]
    idx = bisect_right(accB, k - tmp) - 1
    if tmp + accB[idx] <= k:
        res = max(res, i + idx)
print(res)

n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
t = sum(B)
# しゃくとり法
res = 0
j = m
for i in range(n + 1):
    while j > 0 and t > k:
        j -= 1
        t -= B[j]
    if t > k:
        break
    res = max(res, i + j)
    if i == n:
        break
    t += A[i]
print(res)

-MAX = 10**18 -# 累積和 -accA, accB = [0] * (n + 1), [0] * (m + 1) -accA[1], accB[1] = A[0], B[0] -for i in range(2, n + 1): -    accA[i] = accA[i - 1] + A[i - 1] -for i in range(2, m + 1): -    accB[i] = accB[i - 1] + B[i - 1] -accA.append(MAX) -accB.append(MAX) -from bisect import bisect_left, bisect_right - +t = sum(B) +# しゃくとり法 +j = m -    tmp = accA[i] -    idx = bisect_right(accB, k - tmp) - 1 -    if tmp + accB[idx] <= k: -        res = max(res, i + idx) +    while j > 0 and t > k: +        j -= 1 +        t -= B[j] +    if t > k: +        break +    res = max(res, i + j) +    if i == n: +        break +    t += A[i]