program ABC172C
    implicit none
    integer(8)::i,j
    integer(8)::N,M,K,best0,ans=0
    integer(8),allocatable,dimension(:)::A,B,As,Bs
    read*,N,M,K
    allocate(A(N))
    allocate(As(N+1))
    allocate(B(M))
    allocate(Bs(M+1))
    read*,A,B
    As(1)=0
    Bs(1)=0
    do i=2,N+1
        As(i)=As(i-1)+A(i-1)
    end do

    do i=2,M+1
        Bs(i)=Bs(i-1)+B(i-1)
    end do

    best0=M+1

    do i=1,N+1
        if(As(i)>K)exit
        do j=best0,1,-1
            if(Bs(j)<=K-As(i))then
                best0=j
                ans=max(ans,i+j-2)
                exit
            end if
        end do
    end do
    print'(i0)',ans
end program ABC172C