program main
    use iso_fortran_env
    implicit none
    integer(int32) :: n, m, k
    integer(int32), allocatable :: a(:), b(:)
    integer(int64), allocatable :: bt(:)
    integer(int64), allocatable :: at, tmp
    integer(int32) :: i, j, jmax, ans

    read *, n, m, k
    allocate(a(n))
    allocate(b(m))
    allocate(bt(0:m))
    bt = 0

    read *, (a(i), i = 1, n)
    read *, (b(i), i = 1, m)

    do i = 1, m
        bt(i) = bt(i-1) + b(i)
    enddo

    i = 0
    ans = 0
    at = 0
    jmax = m
    do while( ( k - at ) >= 0 )
        tmp = k - at
        do j = jmax, 0, -1
            if ( bt(j) <= tmp ) exit
        enddo

        if ( ans < (i+j) ) ans = i + j
        i = i + 1
        jmax = j
        at = at + a(i)
        if ( i > n ) exit
    enddo

    print *, ans

end program main