program tsundoku
  implicit none
  integer :: n, m, i, h = 0, l, r, p
  integer(8) :: k, t
  integer(8), dimension(0:200001) :: a = 0, b = 0, x = 0, y = 0
  read(*,*) n, m, k
  read(*,*) a(1:n)
  read(*,*) b(1:m)
  do i = 1, n
    x(i) = x(i - 1) + a(i)
  end do
  do i = 1, m
    y(i) = y(i - 1) + b(i)
  end do
  do i = 0, n
    t = k - x(i)
    if (t < 0) exit
    l = 0
    r = m + 1
    do while (r - l > 1)
      p = (l + r) / 2
      if (y(p) <= t) then
        l = p
      else
        r = p
      end if
    end do
    h = max(h, i + l)
  end do
  write(*,'(i0)') h
end program tsundoku