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

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

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

asum=[0]

bsum=[0]

current=0

for i in range(n):

  current+=a[i]

  asum.append(current)

current=0

pointer=0

for i in range(m):

  current+=b[i]

  bsum.append(current)

for i in range(n+1):

  if asum[i]>k:

    pointer=i-1

    break

  if i==n:

    pointer=n

ans=pointer

bpointer=0

for i in range(pointer,-1,-1):

  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:

    bpointer+=1

    if bpointer==m+1:

      break

  bpointer-=1

  ans=max(ans,i+bpointer)

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

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

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

asum=[0]

bsum=[0]

current=0

for i in range(n):

  current+=a[i]

  asum.append(current)

current=0

for i in range(m):

  current+=b[i]

  bsum.append(current)

pointer=0

for i in range(n+1):

  if asum[i]>k:

    pointer=i-1

    break

  if i==n:

    pointer=n

ans=pointer

bpointer=0

for i in range(pointer,-1,-1):

  while bpointer<m and bsum[bpointer+1]+asum[i]<=k:

    bpointer+=1

  ans=max(ans,i+bpointer)

print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
asum = [0]
bsum = [0]
current = 0
for i in range(n):
    current += a[i]
    asum.append(current)
current = 0
pointer = 0
for i in range(m):
    current += b[i]
    bsum.append(current)
for i in range(n + 1):
    if asum[i] > k:
        pointer = i - 1
        break
    if i == n:
        pointer = n
ans = pointer
bpointer = 0
for i in range(pointer, -1, -1):
    while bpointer < m + 1 and bsum[bpointer] + asum[i] <= k:
        bpointer += 1
        if bpointer == m + 1:
            break
    bpointer -= 1
    ans = max(ans, i + bpointer)
print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
asum = [0]
bsum = [0]
current = 0
for i in range(n):
    current += a[i]
    asum.append(current)
current = 0
for i in range(m):
    current += b[i]
    bsum.append(current)
pointer = 0
for i in range(n + 1):
    if asum[i] > k:
        pointer = i - 1
        break
    if i == n:
        pointer = n
ans = pointer
bpointer = 0
for i in range(pointer, -1, -1):
    while bpointer < m and bsum[bpointer + 1] + asum[i] <= k:
        bpointer += 1
    ans = max(ans, i + bpointer)
print(ans)

-pointer = 0 +pointer = 0 -    while bpointer < m + 1 and bsum[bpointer] + asum[i] <= k: +    while bpointer < m and bsum[bpointer + 1] + asum[i] <= k: -        if bpointer == m + 1: -            break -    bpointer -= 1