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

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

    var takeB = m
    var timeSumA = 0L
    var timeSumB = bList.sum()
    var answer = 0

    for (takeA in 0..n) {
        while (timeSumA + timeSumB > k && takeB > 0) {
            timeSumB -= bList[takeB - 1]
            takeB--
        }

        if (timeSumA + takeB > k) break
        
        answer = Math.max(answer, takeA + takeB)

        if (takeA in aList.indices) timeSumA += aList[takeA]
    }

    println(answer)
}
