//object C {
object Main {
  import InOut._
  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val as = nextInts(n)
    val bs = nextLongs(m)
    val bSums = bs.scan(0L)(_ + _)

    @annotation.tailrec
    def binSearch(low: Long, hi: Long, limit: Long): Long = {
      if (hi < low) low
      else {
        val mid = (low + hi) / 2
        if (bSums(mid.toInt) > limit) binSearch(low, mid - 1, limit)
        else binSearch(mid + 1, hi, limit)
      }
    }
//println(bSums.mkString(" "))
    var aSum = 0L
    var max = binSearch(0, m, k) - 1
    for (i <- as.indices) {
      aSum += as(i)
      if (aSum <= k) {
        val j = binSearch(0, m, k - aSum)
//        println(i, aSum, j, k - aSum)
//        if (j < m && bSums(j.toInt) > k - aSum) j -= 1
        val x = i + j
        if (x > max) {
          max = x
        }
      }
    }

    out.println(max)

    out.flush()
  }
 
  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}
