program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,m,k,cnt=0,time,ia,i,ib, mc=0
    integer(int64), allocatable:: a(:), b(:), dp(:,:)

    read*, n, m, k
    allocate(a(n), b(m), dp(0:n,0:m))
    read*, a(1:n)
    read*, b(1:m)
    

    time = sum(a)
    cnt = n
    ia=n

    do while (time > k)
        time = time - a(ia)
        ia=ia-1
        cnt=cnt-1
    end do

    ib=1

    do while (ib <= m)
        if (time+b(ib) > k) exit
        time=time+b(ib)
        ib=ib+1
        cnt=cnt+1
    end do

    mc = cnt

    do i=ia,1,-1
        cnt=cnt-1
        time=time-a(i)
        do while (ib <= m)
            if (time + b(ib) > k) exit
            time=time+b(ib)
            ib=ib+1
            cnt=cnt+1
        end do
        mc = max(mc, cnt)
    end do
    print'(i0)', mc
end program main