fun main() {
    val (_, _, k) = readInts().map { it.toLong() }
    val a = readInts().map { it.toLong() }.toMutableList()
    val b = readInts().map { it.toLong() }.toMutableList()

    a.forEachIndexed { index, _ -> if (index > 0) a[index] += a[index - 1] }
    b.forEachIndexed { index, _ -> if (index > 0) b[index] += b[index - 1] }

    fun getVal(list: List<Long>, index: Int): Long {
        return if (index in list.indices) list[index] else 0
    }

    var maxRead = 0
    var total = 0L
    var pointerB = b.size - 1
    for (i in -1 until a.size) {
        if (i >= 0) total = a[i]
        while (pointerB >= 0 && total + b[pointerB] > k) pointerB--
        total = getVal(a, i) + getVal(b, pointerB)
        if (total <= k) maxRead = maxOf(i + pointerB + 2, maxRead)
        else break
    }

    println(maxRead)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInts() = readStrings().map { it.toInt() }