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

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

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

A=[0]

B=[0]

ans=0

j=M

for i in range(N):

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

for i in range(M):

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

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)

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))

n,m,k=MI()

a=[0]+LI()

b=[0]+LI()

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

  a[i]+=a[i-1]

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

  b[i]+=b[i-1]

ans=0

j=m

for i in range(n+1):

  if a[i]>k:

    continue

  while a[i]+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 = [0]
B = [0]
ans = 0
j = M
for i in range(N):
    A.append(A[i] + a[i])
for i in range(M):
    B.append(B[i] + b[i])
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)

def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


n, m, k = MI()
a = [0] + LI()
b = [0] + LI()
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
ans = 0
j = m
for i in range(n + 1):
    if a[i] > k:
        continue
    while a[i] + 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 = [0] -B = [0] +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +n, m, k = MI() +a = [0] + LI() +b = [0] + LI() +for i in range(1, n + 1): +    a[i] += a[i - 1] +for i in range(1, m + 1): +    b[i] += b[i - 1] -j = M -for i in range(N): -    A.append(A[i] + a[i]) -for i in range(M): -    B.append(B[i] + b[i]) -for i in range(N + 1): -    if A[i] > K: -        break -    while A[i] + B[j] > K: +j = m +for i in range(n + 1): +    if a[i] > k: +        continue +    while a[i] + b[j] > k: