

fun main() {
    val (n, m, k) = readLine()!!.trim().split(' ').map(String::toInt)
    val aBooks = readLine()!!.trim().split(' ').map(String::toInt).toIntArray()
    val bBooks = readLine()!!.trim().split(' ').map(String::toInt).toIntArray()
    var bSum = bBooks.fold(0L){acc, b -> acc + b}
    var bPos = m - 1
    var aSum = 0L
    while (bPos >= 0 && bSum > k) {
        bSum -= bBooks[bPos--]
    }
    var max = bPos + 1
    for (aPos in aBooks.indices) {
        aSum += aBooks[aPos]
        if (aSum > k) break
        while (bPos >= 0 && aSum + bSum > k) {
            bSum -= bBooks[bPos--]
        }
        max = maxOf(max, aPos + bPos + 2)
    }
    println(max)
}
