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 = LongArray(n + 1)
    for (i in 0 until n) {
        sa[i + 1] = sa[i] + a[i]
    }
    val sb = LongArray(m + 1)
    for (i in 0 until m) {
        sb[i + 1] = sb[i] + b[i]
    }

    var ans = 0
    var j = m
    for (i in 0..n) {
        if (sa[i] > k) break
        while (sb[j] > k - sa[i]) {
            j--
        }
        ans = max(ans, i + j)
    }

    println(ans)
}