fun main() = Thread(null, ::abc172c, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc172c() {
    val (n, _, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }
    val bList = readLine()!!.split(' ').map { it.toLong() }

    val cSumA = aList.scan(0L, Long::plus).toLongArray()
    val cSumB = bList.scan(0L, Long::plus).toLongArray()

    var answer = 0

    for (takeA in 0..n) {
        val takeTimeWithA = cSumA[takeA]
        if (takeTimeWithA > k) continue
        val takeB = binarySearch(cSumB, k - takeTimeWithA) - 1
        answer = Math.max(answer, takeA + takeB)
    }

    println(answer)
}

private fun binarySearch(list: LongArray, key: Long): Int {
    var ng = -1
    var ok = list.size

    while (ok - ng > 1) {
        val mid = (ok + ng) / 2
        if (list[mid] > key) ok = mid else ng = mid
    }
    return ok
}
