program gluttony
  implicit none
  integer :: n, i
  integer(8) :: k, l = -1_8, r = 1000000000000_8, m, s
  integer(8), dimension(200000) :: a = 0_8, f = 0_8
  read(*,*) n, k
  read(*,*) a(1:n)
  if (sum(a(1:n)) <= k) then
    write(*,'(i0)') 0
    stop
  end if
  read(*,*) f(1:n)
  call bitonic_sort(a(1:n),.true.)
  call bitonic_sort(f(1:n),.false.)
  do while (r-l > 1_8)
    m = (l+r)/2_8
    s = 0_8
    do i = 1, n
      if (a(i)*f(i) <= m) cycle
      s = s+(a(i)*f(i)-m+f(i)-1_8)/f(i)
    end do
    if (s <= k) then
      r = m
    else
      l = m
    end if
  end do
  write(*,'(i0)') r
contains
  recursive subroutine bitonic_sort(a,ascend)
    integer(8), intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n
    n = size(a)
    if (n == 1) return
    call bitonic_sort(a(1:n/2),.not.ascend)
    call bitonic_sort(a(n/2+1:n),ascend)
    call bitonic_merge(a,ascend)
  end
  recursive subroutine bitonic_merge(a,ascend)
    integer(8), intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n, m, i
    n = size(a)
    if (n == 1) return
    m = 1
    do while (2*m < n)
      m = 2*m
    end do
    do i = 1, n-m
      if ((a(i) > a(i+m)) .eqv. ascend) then
        a(i) = xor(a(i),a(i+m))
        a(i+m) = xor(a(i),a(i+m))
        a(i) = xor(a(i),a(i+m))
      end if
    end do
    call bitonic_merge(a(1:m),ascend)
    call bitonic_merge(a(m+1:n),ascend)
  end
end program gluttony