object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M, K = sc.nextInt()
  val as = Array.fill(N)(sc.nextLong()).scanLeft(0L)(_ + _)
  val bs = Array.fill(M)(sc.nextLong()).scanLeft(0L)(_ + _)
  var j = M
  val result = (0 to N).foldLeft(0) { (acc, i) =>
    if (as(i) <= K) {
      while (bs(j) > K - as(i)) j -= 1
      Math.max(acc, i + j)
    } else acc
  }
  println(result)
}
