fun main(args: Array<String>) {
    // var numberTests = readLine()!!.toInt()
    // var results = mutableListOf<String>()

    // for (i in 0..numberTests-1) {
    var nmk = readLine()!!.split("\\s+".toRegex())
    var n = nmk[0].toInt()
    var m = nmk[1].toInt()
    var k = nmk[2].toLong()

    var aarray = readLine()!!.split("\\s+".toRegex()).map {it.toLong()}
    var barray = readLine()!!.split("\\s+".toRegex()).map {it.toLong()}

    
    val result = experiment(n, m, k, aarray, barray)
    // results.add(result)
    // }

    // for (result in results) {
        println(result)
    // }
}

fun experiment(n: Int, m: Int, k: Long, aarray : List<Long>, barray : List<Long>) : String {

    var result = 0

    val maxAandSum = calcNumMax(k , aarray)
    val maxBandSum = calcNumMax(k , barray)

    // println("${maxAandSum.first} , ${maxBandSum.first}")

    val minimax = maxAandSum
    var currentMaxNum = minimax.first
    var currentSumNum = minimax.second
    val anotherMax = maxBandSum.first
    var currentSumAnother : Long = 0
    var currentNum =  currentMaxNum
    var currentAnotherNum = 0

    for (i in 0..anotherMax-1) {
        if (currentSumNum + currentSumAnother + barray[i] > k) {
            // 超えるので、今の結果を記録
            if (currentMaxNum < currentNum + i) currentMaxNum = currentNum + i
            while (currentSumNum + currentSumAnother + barray[i] > k) {
                currentSumNum -= aarray[currentNum-1]
                currentNum -= 1
            }
        } else {
            // 超えないので、冊数積んで記録
            if (currentMaxNum < currentNum + i+1) currentMaxNum = currentNum + i + 1
        }
        
        currentSumAnother += barray[i]


        // println("$i $currentMaxNum $currentSumNum $currentSumAnother")
    }

    return currentMaxNum.toString()
}

fun calcNumMax(k: Long , arr : List<Long> ) : Pair<Int, Long> {
    var maxNum : Int = 0
    var sumCurrent : Long = 0
    for (i in 0..arr.size-1) {
        if (sumCurrent + arr[i] > k) {return Pair(i, sumCurrent)}
        else {sumCurrent +=  arr[i] }
    } 
    return Pair(arr.size, sumCurrent)
}