awk -M '\
NR==1{N=$1; M=$2; K=$3}
NR==2{split($0,A)}
NR==3{split($0,B)}
END{
    i=k=1
    ans=0
    while(1){
        if(A[i]<B[k] && i<=N){
            s=A[i]
            i++
        }else if(k<=M){
            s=B[k]
            k++
        }else{
            print ans;
            exit;
        }
        if(sum+s>K){
            print ans
            exit;
        }
        sum+=s;
        ans++;
    }
}'