"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    let K = parseInt(arg[0].split(" ")[2]);
    
    const A = arg[1].split(" ").map(n=>parseInt(n));
    const B = arg[2].split(" ").map(n=>parseInt(n));
    
    let answer = 0;
    
    let tempA = 0;
    let cntA = 0;
    
    let tempB = 0;
    let cntB = 0;
    
    for(let i=0; i<N; i++) {
        if(tempA + A[i] > K) break;
        
        tempA += A[i];
        cntA++;
    }
    
    for(let i=0; i<M; i++) {
        if(tempB + B[i] > K) break;
        
        tempB += B[i];
        cntB++;
    }
    
    let firstTake;
    let rest;
    
    if(cntA === cntB) {
        const restA = K - tempA;
        const restB = K - tempB;
        
        if(restA > restB) {
            firstTake = "A";
        } else {
            firstTake = "B";
        }
        
    } else if(cntA > cntB) {
        firstTake = "A";
    } else {
        firstTake = "B";
    }
    
    let resultA = 0;
    let restA;
    
    let resultB = 0;
    let restB;
    
    // if(firstTake === "A") {
        resultA += cntA;
        restA = K - tempA;
        
        let i = 0;
        // console.log("Aを優先で取り、" + cntA + "個とった");
        
        while(B[i] <= restA) {
            if(i === M) break;
            resultA++;
            restA -= B[i];
            i++;
        }
        
        // console.log("追加でBからとって" + resultA + "個になった");
    // } else {
        resultB += cntB;
        restB = K - tempB;
        
        let j = 0;
        // console.log("Bを優先で取り、" + cntB + "個とった");
        
        while(A[j] <= restB) {
            if(j === N) break;
            resultB++;
            restB -= A[j];
            j++;
        }
        
        // console.log("追加でAからとって" + resultB + "個になった");
    // }
    
    
    console.log(Math.max(resultA, resultB));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
