program c172

implicit none
integer :: n, m, k, i, j, t
integer, allocatable :: a(:), b(:)

read *, n, m, k

allocate(a(0:n-1))
allocate(b(0:m-1))

read *, a(:)
read *, b(:)

t = 0
i = 0
j = 0

do 
 if (a(i) <= b(j) .and. t + a(i) <= k .and. i < n) then
  !print *, a(i)
  t = t + a(i)
  i = i + 1
 else if (t + b(j) <= k .and. j < m) then
  !print *, b(j)
  t = t + b(j)
  j = j + 1
 else
  exit
 end if 
end do

print *, i + j

end program c172