program main
  implicit none
  integer(8) i, N, M, K, ans, AllA, ta, tb, na, nb, j
  integer(8),allocatable :: A(:),B(:)
  read(*, *) N, M, K
  allocate(A(N))
  allocate(B(M))
  read(*, *) (A(i), i = 1,N)
  read(*, *) (B(i), i = 1,M)
  ans = 0
  tb = 0
  !全てBのとき
  do i = 1,M
    if (tb + B(i) > K) then
      exit
    else 
      tb = tb + B(i)
      ans = ans + 1
    end if
  end do
  !Aを一冊づつ増やす
  ta = 0
  tb = sum(B(1:ans))
  na = 0
  nb = ans
  do i = 1,N
    na = na + 1
    ta = sum(A(1:na))
    if (ta > K) then
      exit
    end if
    !nb = 0
    !tb = 0
    do
      if (tb + ta <= K) then
        exit
      else
        tb = tb - B(nb)
        nb = nb - 1
        !tb = tb + B(j)
      endif
    enddo
    if (ans < na + nb) then
      ans = na + nb
    end if
  enddo
  write(*, *) ans
end program main
