import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val m = sc.nextInt()
  val k = sc.nextLong()
  val a = (1..n).map { sc.nextLong() }
  val b = (1..m).map { sc.nextLong() }


  val sumA = Array(n+1) { 0L }
  val sumB = Array(m+1) { 0L }


  for (i in 0 until n) {
    sumA[i+1] = sumA[i] + a[i]
  }
  for (i in 0 until m) {
    sumB[i+1] = sumB[i] + b[i]
  }

  var maxM = 0
  for (i in 0..m) {
    if (sumB[i] > k) {
      break
    }
    maxM = i
  }

  var ans = 0
  for (i in 0..n) {
    if (sumA[i] > k) {
      break
    }
    while (sumB[maxM] > k - sumA[i]) {
      maxM--
    }
    ans = Math.max(ans, i + maxM)
  }

  println(ans)
}
