fun main(args : Array<String>) {
    val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toLong() }
    val bb = readLine()!!.split(" ").map { it.toLong() }

    val aTime = mutableListOf<Long>()
    aTime.add(aa[0])
    for (i in 1 until aa.size) {
        aTime.add(aTime[i-1] + aa[i])
    }
    aTime.add(0, 0)

    val bTime = mutableListOf<Long>()
    bTime.add(bb[0])
    for (i in 1 until bb.size) {
        bTime.add(bTime[i-1] + bb[i])
    }
    bTime.add(0, 0)

    var cnt = 0
    var lastBIdx = m

    for (i in 0..n) {
        val at = aTime[i]
        if (at > k) break

        val rest = k - at
        var tmpCnt = i

        inner@for (j in lastBIdx downTo 0) {
            if (bTime[j] <= rest) {
                tmpCnt += j
                lastBIdx = j
                break@inner
            }
        }

        cnt = Math.max(cnt, tmpCnt)
    }

    println(cnt)
}