function Main(input) {
    input = input.trim().split('\n');
    const k = parseInt(input[0].split(' ')[2], 10);
    const a = input[1].split(' ');
    const b = input[2].split(' ');

    let t = 0;
    for(let i=0; i<b.length; i++){
        t += parseInt(b[i], 10);
    }

    let j = b.length;
    let ans = 0;
    for(let i=0; i<=a.length; i++){
        while(j > 0 && t > k) {
            j--;
            t -= parseInt(b[j]);
        }
        if(t > k) break;
        if(ans < i+j) ans = i+j;
        if(i === a.length) break;
        t += parseInt(a[i], 10);
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
