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

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

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



a,b = [0], [0]



for i in range(n):

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

for j in range(m):

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

    

ans, j = 0, m

for i in range(n+1):

    if a[i] > k:

        break

    while a[i] + b[j] > k:

        j -= 1

    ans = max(ans, i+j)

print(ans)
import itertools



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

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

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



acc_A = [0]+list(itertools.accumulate(A))

acc_B = [0]+list(itertools.accumulate(B))

    

ans, j = 0, m

for i in range(n+1):

    if acc_A[i] > k:

        break

    while acc_A[i] + acc_B[j] > k:

        j -= 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()))
a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for j in range(m):
    b.append(b[j] + B[j])
ans, j = 0, m
for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    ans = max(ans, i + j)
print(ans)

import itertools

n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
acc_A = [0] + list(itertools.accumulate(A))
acc_B = [0] + list(itertools.accumulate(B))
ans, j = 0, m
for i in range(n + 1):
    if acc_A[i] > k:
        break
    while acc_A[i] + acc_B[j] > k:
        j -= 1
    ans = max(ans, i + j)
print(ans)

+import itertools + -a, b = [0], [0] -for i in range(n): -    a.append(a[i] + A[i]) -for j in range(m): -    b.append(b[j] + B[j]) +acc_A = [0] + list(itertools.accumulate(A)) +acc_B = [0] + list(itertools.accumulate(B)) -    if a[i] > k: +    if acc_A[i] > k: -    while a[i] + b[j] > k: +    while acc_A[i] + acc_B[j] > k: