import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (n, m, k) = readLongList()
    val aList = readLongList()
    val bList = readLongList()
    val aSums = aList.fold(mutableListOf(0L)) { acc, value ->
        acc += acc.last() + value
        acc
    }
    val bSums = bList.fold(mutableListOf(0L)) { acc, value ->
        acc += acc.last() + value
        acc
    }

//    累積和で二分探索
//     nlog(n)
    var ans = 0
    for ((i, a) in aSums.withIndex()) {
        var left = -1
        var right = bSums.size
        while (right - left > 1) {
            val mid = (right + left) / 2
            if (a + bSums[mid] > k) right = mid else left = mid
        }

//        if (left in bSums.indices) {
//            println("${aSums} ${i} ${a}")
//            println("${bSums} ${left} ${bSums[left]}")
//            println()
//        }
        ans = if (left in bSums.indices) max(ans, i + left) else ans
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)
