function main(input) {
    const [n, m, k] = shaping(input[0]);
    const a = shaping(input[1]);
    const b = shaping(input[2]);
    if (a[0] > k && b[0] > k) { return console.log(0); };
    let timeA = new Array();
    let timeB = new Array();
    let sumTime = 0;
    let ans = new Array();
    //必要最低限のAの累積和
    for (let i = 0; i < n; i++){
        sumTime += a[i];
        if (sumTime >= k) {
            if (sumTime = k) {
                ans.push(timeA.length);
                break;
            } else {
                ans.push(timeA.length - 1);
                break;
            }
        }
        timeA.push(sumTime);
    }
    sumTime = 0;
    for (let i = 0; i < m; i++){
        sumTime += b[i];
        if (sumTime >= k) {
            if (sumTime = k) {
                ans.push(timeB.length);
                break;
            } else {
                ans.push(timeB.length - 1);
                break;
            }
        }
        timeB.push(sumTime);
    }
    console.log(timeA);
    console.log(timeB);
    
    let i = 0;
    let j = timeB.length-1;

    while (i < timeA.length) {
        while (j > -1) {
            if (timeB[j] <= k - timeA[i]) {
                ans.push(i + j + 2);
                break;
            } else {
                j--;
            }
        }
        i++;
    }
    console.log(Math.max(...ans));
}
    
function shaping(arr) { 
    return arr.split(' ').map(Number);
}


main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));
