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

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

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

AS=[0]

BS=[0]

for i in A:

  if i+AS[-1]<=k:

    AS.append(i+AS[-1])

  else:break

for i in B:

  if i+BS[-1]<=k:

    BS.append(i+BS[-1])

  else:break

r,j=0,len(BS)-1

for i in range(len(AS)):

  while AS[i]+BS[j]>k:

    j-=1

  r=max(r,i+j)

print(r)
from itertools import accumulate

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

A=list(accumulate(list(map(int,input().split())),initial=0))

B=list(accumulate(list(map(int,input().split())),initial=0))

r,j=0,m

for i in range(n+1):

  if A[i]>k:

    break

  while A[i]+B[j]>k:

    j-=1

  r=max(r,i+j)

print(r)
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AS = [0]
BS = [0]
for i in A:
    if i + AS[-1] <= k:
        AS.append(i + AS[-1])
    else:
        break
for i in B:
    if i + BS[-1] <= k:
        BS.append(i + BS[-1])
    else:
        break
r, j = 0, len(BS) - 1
for i in range(len(AS)):
    while AS[i] + BS[j] > k:
        j -= 1
    r = max(r, i + j)
print(r)

from itertools import accumulate

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

+from itertools import accumulate + -A = list(map(int, input().split())) -B = list(map(int, input().split())) -AS = [0] -BS = [0] -for i in A: -    if i + AS[-1] <= k: -        AS.append(i + AS[-1]) -    else: +A = list(accumulate(list(map(int, input().split())), initial=0)) +B = list(accumulate(list(map(int, input().split())), initial=0)) +r, j = 0, m +for i in range(n + 1): +    if A[i] > k: -for i in B: -    if i + BS[-1] <= k: -        BS.append(i + BS[-1]) -    else: -        break -r, j = 0, len(BS) - 1 -for i in range(len(AS)): -    while AS[i] + BS[j] > k: +    while A[i] + B[j] > k: