program gluttony
    implicit none
    integer(8):: n,i
    integer(8), allocatable:: a(:), f(:)
    integer(8):: k, ans

    read*, n, k
    allocate(a(n), f(n))
    read*, a(:)
    read*, f(:)
    call merge_sort(a(:), 1_8, n)
    call merge_sort(f(:), 1_8, n)
    f(:) = [(f(i), i=n,1,-1)]
    print*, a(:)
    print*, f(:)
    block
        integer(8):: l=-1, r=1e12, c
        do while(l+1 < r)
            ans = 0
            c = (l+r)/2
            do i=1, n
                ans = ans + max(0_8, a(i) - c/f(i))
            end do
            if (ans <= k) then
                r = c
            else
                l = c
            end if
        end do
        print*, r
    end block

    contains
    recursive subroutine merge_sort(ar,start,end)
        integer(8):: ar(:), start, end

        if (end-start < 2) then
            if (ar(start) > ar(end)) then
            block; integer(8):: tmp
                tmp = ar(start)
                ar(start) = ar(end)
                ar(end) = tmp
            end block; end if
            return
        end if

        block
            integer(8):: c
            c = (start+end)/2
            call merge_sort(ar(:), start, c)
            call merge_sort(ar(:), c+1, end)
            call merge(ar(:), start, c, end)
        end block
    end subroutine

    subroutine merge(ar, start, c, end)
        integer(8):: ar(:), start, c, end
        integer(8),pointer:: tmp(:)
        allocate(tmp(end-start+1))

        block
            integer(8):: l,r,ti
            l=start
            r=c+1
            ti=1
            do while(l <= c .and. r <= end)
                if (ar(l) <= ar(r)) then
                    tmp(ti) = ar(l)
                    l=l+1
                else
                    tmp(ti) = ar(r)
                    r=r+1
                end if
                ti=ti+1
            end do

            if (r > end) then
                tmp(ti:) = ar(l:c)
            else
                tmp(ti:) = ar(r:end)
            end if
        end block

        ar(start:end) = tmp(:)
        deallocate(tmp)
    end subroutine
end program gluttony