import kotlin.math.max

fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val (n, m, k) = longList()
    val a = longList()
    val b = longList()
    var t = 0L
    var count = 0
    run {
        a.forEach {
            t += it
            if (t >= k) {
                if (t == k) {
                    count++
                } else {
                    t -= it
                }
                return@run
            }
            count++
        }
    }
    var countMax = count
    var count2 = count
    run {
        b.forEach {
            t += it
            while (t > k) {
                if (count2 == 0) {
                    return@run
                } else {
                    count2--
                    count--
                    t -= a[count2]
                }
            }
            count++
            countMax = max(count, countMax)
        }
    }
    println((countMax).toString())
}
