function main(arg) {
    let [N,M,K] = arg.split("\n")[0].split(" ").map(Number)
    let A = arg.split("\n")[1].split(" ").map(Number)
    let B = arg.split("\n")[2].split(" ").map(Number)


    let a = [A[0]]
    for(let i=1; i<N; i++) {
        a.push(a[i-1]+A[i])
    }
    //console.log(a)
    let b = [B[0]]
    for(let i=1; i<M; i++) {
        b.push(b[i-1]+B[i])
    }
    //console.log(b)
    
    let j = M-1
    let sum = 0
    for(let i=0; i<N; i++) {
        let tmpB = K - a[i]
        if(tmpB < 0)break
        while(b[j] > tmpB) {
            //console.log(b[j])
            j--
        }
        sum = Math.max(i+1+j+1, sum)
        //console.log(`  tmpB=${tmpB}, i=${i}, j=${j}`)
    }
    console.log(sum)
    
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
