import kotlin.math.max

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun List<Long>.upperBound(element: Long, fromIndex: Int = 0, toIndex: Int = size): Int {
    return binarySearch(element, Comparator { x, y ->
        if (x > y) {
            1
        } else {
            -1
        }
    }, fromIndex, toIndex).inv()
}

@ExperimentalStdlibApi
fun main() {
    val (_, _, k) = readLongList()
    val a = readLongList()
    val b = readLongList()

    val ar = listOf(0L) + a.scanReduce { acc, l -> acc + l }
    val br = listOf(0L) + b.scanReduce { acc, l -> acc + l }

    var res = 0
    for (aCount in ar.indices) {
        val remain = k - ar[aCount]
        if (remain < 0) continue
        val bCount = br.upperBound(remain) - 1
        res = max(res, aCount + bCount)
    }

    print(res)
}