fun main() {
    val builder = StringBuilder()

    val (n, m, k) = readInputLine().split(" ").map { it.toLong() }

    val aArr = readInputLine().split(" ").map { it.toLong() }.toLongArray()
    val bArr = readInputLine().split(" ").map { it.toLong() }.toLongArray()

    var accumTime = 0L
    var a = 0
    var b = 0

    // ひとまずAをできるだけ読む
    for (i in 0 until n.toInt()) {
        if (accumTime + aArr[i] <= k) {
            a++
            accumTime += aArr[i]
        } else {
            break
        }
    }

    // 残った時間でBをできるだけ読む
    for (i in 0 until m.toInt()) {
        if (accumTime + bArr[i] <= k) {
            b++
            accumTime += bArr[i]
        } else {
            break
        }
    }

    // Aを読む量を減らしてBを読む量をそれ以上にできるならば入れ替え
    var downAccumTime = 0L
    var upAccumTime = 0L

    var aTmp = a
    var bTmp = b

    while (aTmp > 0 && bTmp != m.toInt()) {
        downAccumTime += aArr[aTmp - 1]
        aTmp--
        while (bTmp != m.toInt()) {
            if (upAccumTime + bArr[bTmp] - downAccumTime + accumTime > k) {
                break
            }
            upAccumTime += bArr[bTmp]
            bTmp++
        }
        if ((a - aTmp < bTmp - b) || ((a - aTmp == bTmp - b) && downAccumTime >= upAccumTime)) {
            accumTime -= downAccumTime - upAccumTime
            a = aTmp
            b = bTmp
            downAccumTime = 0L
            upAccumTime = 0L
        }
    }

    builder.appendln(a + b)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
