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)(_ + _)

  @scala.annotation.tailrec
  def loop(diff: Long, j: Int): Int = if (diff < bs(j)) loop(diff, j - 1) else j

  val (max, _) = as.indices.foldLeft((0, M)) {
    case ((acc, m), i) =>
      if (K < as(i)) acc -> m
      else {
        val j = loop(K - as(i), m)
        acc.max(i + j) -> j
      }
  }
  println(max)
}
