import kotlin.math.max

fun main() {
    val (n, m, k) = readLongList()
    val a = readLongList()
    val b = readLongList()
    var time = 0L
    var countA = 0
    run {
        a.forEach{
            time += it
            if(time >= k) {
                if(time == k) {
                    countA++
                } else {
                    time -= it
                }
                return@run
            }
            countA++
        }
    }
    var countMax = countA
    var countB = countA
    run {
        b.forEach {
            time += it
            while(time > k) {
                if(countB == 0) {
                    return@run
                } else {
                    countB--
                    countA--
                    time -= a[countB]
                }
            }
            countA++
            countMax = max(countA, countMax)
        }
    }
    println(countMax.toString())
}

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)