import kotlin.math.max

fun main() {
    val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    val b = readLine()!!.split(" ").map { it.toInt() }

    val sa = Array(n + 1) { 0L }
    for (i in 0 until n) sa[i + 1] = sa[i] + a[i]

    val sb = Array(m + 1) { 0L }
    for (i in 0 until m) sb[i + 1] = sb[i] + b[i]

    var best = -1
    for (ca in 0..n) {

        val rest = k - sa[ca]
        if (rest < 0) continue

        var cb = sb.binarySearch(rest)
        if (cb < 0) cb = -cb - 2

        best = max(best, ca + cb)
    }

    println(best)
}