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

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

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

c=0

k=M

import numpy as np

A=np.array(A).cumsum()

B=np.array(B).cumsum()

for i in range(N):

  d=K-A[i]

  if d<0:

    for j in reversed(list(range(M))):

      if K-B[j]>=0:

        if c<j+1:

          c=j+1

        break

    break

  else:

    for j in reversed(list(range(k))):

      if d>=B[j]:

        if c<i+j+2:

          c=i+j+2

        k=j+1

        break

    if d<B[0]:

      if c<i+1:

        c=i+1

      k=0

for j in reversed(list(range(M))):

  if K-B[j]>=0:

    if c<j+1:

      c=j+1

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

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

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

c=0

A.insert(0,0)

B.insert(0,0)

import numpy as np

A=np.array(A).cumsum()

B=np.array(B).cumsum()



for i in range(N+1):

  d=K-A[i]

  for j in reversed(list(range(M+1))):

    if d-B[j]>=0:

      if c<i+j:

        c=i+j

      M=j

      break

print(c)
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
k = M
import numpy as np

A = np.array(A).cumsum()
B = np.array(B).cumsum()
for i in range(N):
    d = K - A[i]
    if d < 0:
        for j in reversed(list(range(M))):
            if K - B[j] >= 0:
                if c < j + 1:
                    c = j + 1
                break
        break
    else:
        for j in reversed(list(range(k))):
            if d >= B[j]:
                if c < i + j + 2:
                    c = i + j + 2
                k = j + 1
                break
        if d < B[0]:
            if c < i + 1:
                c = i + 1
            k = 0
for j in reversed(list(range(M))):
    if K - B[j] >= 0:
        if c < j + 1:
            c = j + 1
print(c)

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
A.insert(0, 0)
B.insert(0, 0)
import numpy as np

A = np.array(A).cumsum()
B = np.array(B).cumsum()
for i in range(N + 1):
    d = K - A[i]
    for j in reversed(list(range(M + 1))):
        if d - B[j] >= 0:
            if c < i + j:
                c = i + j
            M = j
            break
print(c)

-k = M +A.insert(0, 0) +B.insert(0, 0) -for i in range(N): +for i in range(N + 1): -    if d < 0: -        for j in reversed(list(range(M))): -            if K - B[j] >= 0: -                if c < j + 1: -                    c = j + 1 -                break -        break -    else: -        for j in reversed(list(range(k))): -            if d >= B[j]: -                if c < i + j + 2: -                    c = i + j + 2 -                k = j + 1 -                break -        if d < B[0]: -            if c < i + 1: -                c = i + 1 -            k = 0 -for j in reversed(list(range(M))): -    if K - B[j] >= 0: -        if c < j + 1: -            c = j + 1 +    for j in reversed(list(range(M + 1))): +        if d - B[j] >= 0: +            if c < i + j: +                c = i + j +            M = j +            break