CodeEff/ECCO huggingface dataset:
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ok = 10**12
ng = -1

while ok-ng>1:
  X = (ok+ng)//2
  tmp = 0
  for i,e in enumerate(A):
    tmp += max(e-X//F[i],0)
  if tmp<=K:
    ok = X
  else:
    ng = X
print(ok)

    
  

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ok = 10**12
ng = -1

while ok-ng>1:
  X = (ok+ng)//2
  tmp = 0
  for i in range(N):
    tmp += max(A[i]-X//F[i],0)
  if tmp<=K:
    ok = X
  else:
    ng = X
print(ok)
# Original solution
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

N,K=list(map(int,readline().split()))
A=list(map(int,readline().split()))
F=list(map(int,readline().split()))
#print(N,K)
#print("A:",A)
#print(F)

A.sort()
F.sort(reverse=True)
#print("A:",A)
#print("F:",F)

left=-1
right=10**18
#right=10**3

while left+1<right:
  mid=(left+right)//2
  tmp=[0]*(N)
  for i in range(N):
    tmp[i]=max(A[i]-mid//F[i],0)
    
  if sum(tmp)<=K:
    right=mid
  else:
    left=mid
  #print("mid:",mid,",tmp:",tmp)
#print("left:",left,",mid:",mid,",right:",right)
print(right)

# Optimized solution
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

N,K=list(map(int,readline().split()))
A=list(map(int,readline().split()))
F=list(map(int,readline().split()))
#print(N,K)
#print("A:",A)
#print(F)

A.sort()
F.sort(reverse=True)
#print("A:",A)
#print("F:",F)

left=-1
right=10**18
#right=10**3

while left+1<right:
  mid=(left+right)//2
  tmp=0
  for i in range(N):
    tmp+=max(A[i]-mid//F[i],0)
    
  if tmp<=K:
    right=mid
  else:
    left=mid
  #print("mid:",mid,",tmp:",tmp)
#print("left:",left,",mid:",mid,",right:",right)
print(right)
# Original solution
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
F=list(map(int,input().split()))
#print(N,K)
#print("A:",A)
#print(F)

A.sort()
F.sort(reverse=True)
#print("A:",A)
#print("F:",F)

left=-1
right=2*10**17
#right=10**3

while left+1<right:
  mid=(left+right)//2
  tmp=0
  for i in range(N):
    tmp+=max(A[i]-mid//F[i],0)
    
  if tmp<=K:
    right=mid
  else:
    left=mid
  #print("mid:",mid,",tmp:",tmp)
#print("left:",left,",mid:",mid,",right:",right)
print(right)

# Optimized solution
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

N,K=list(map(int,readline().split()))
A=list(map(int,readline().split()))
F=list(map(int,readline().split()))
#print(N,K)
#print("A:",A)
#print(F)

A.sort()
F.sort(reverse=True)
#print("A:",A)
#print("F:",F)

left=-1
right=N*A[-1]*F[0]
#right=10**3

while left+1<right:
  mid=(left+right)//2
  tmp=0
  for i in range(N):
    tmp+=max(A[i]-mid//F[i],0)
    
  if tmp<=K:
    right=mid
  else:
    left=mid
  #print("mid:",mid,",tmp:",tmp)
#print("left:",left,",mid:",mid,",right:",right)
print(right)
# Original solution
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
F = sorted(F)[::-1]

h = []
for i in range(N):
  a, f = A[i], F[i]
  heappush(h, (- a * f, a, f))
  
while K > 0:
  x, y, z = heappop(h)
  if x == 0:
    break
  else:
    heappush(h, (- (y - 1) * z, (y - 1), z))
    K -= 1
    
x, y, z = heappop(h)
print((-x))

# Optimized solution
import sys
input = sys.stdin.buffer.readline

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
F = sorted(F)[::-1]

left = -1
right = 10 ** 18

while left + 1 < right:
  mid = (left + right) // 2
  tmp = 0
  for i in range(N):
    a, f = A[i], F[i]
    if a * f > mid:
      tmp += -(-(a * f - mid) // f)
  if tmp <= K:
    right = mid
  else:
    left = mid
    
print(right)
# Original solution
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))

As.sort()
Fs.sort(reverse=True)
maxAF = max([A*F for A, F in zip(As, Fs)])

def isOK(X):
    rest = K
    for A, F in zip(As, Fs):
        if A*F > X:
            A2 = X//F
            d = A-A2
            if d > rest:
                return False
            rest -= d
    return True

ng, ok = -1, maxAF
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)


# Optimized solution
def solve():
    N, K = list(map(int, input().split()))
    As = list(map(int, input().split()))
    Fs = list(map(int, input().split()))

    As.sort()
    Fs.sort(reverse=True)

    def isOK(score):
        d = 0
        for A, F in zip(As, Fs):
            if A*F > score:
                d += -(-(A*F-score) // F)
        return d <= K

    ng, ok = -1, 10**12
    while abs(ok-ng) > 1:
        mid = (ng+ok) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid

    print(ok)


solve()
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12


def func(x):
    k = 0  # 修行回数初期化
    for a, f in zip(A, F): # O(N)
        if a <= x // f:  # (Ai-Ki)*Fi<=x Ki=0なら次 (a*f<=xの変形)
            continue
        k += a - x // f
        # else (Ai-Ki)*Fi<=x を満たすようにKiを設定。つまり修行回数にKiを加算。
    if k <= K:
        return 1
    return 0


while (r - l > 1): # O(logx)
    mid = (l + r) // 2
    if func(mid):
        r = mid
    else:
        l = mid


print(r)

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12


def func(x):  # a, x, kは全て整数ということに注意(//またはint())
    k = 0  # 修行回数初期化
    for a, f in zip(A, F):  # O(N)
        e = x // f
        if a <= e:  # (Ai-Ki)*Fi<=x Ki=0なら次 (a*f<=xの変形)
            continue
        k += a - e
        # else (Ai-Ki)*Fi<=x を満たすようにKiを設定。つまり修行回数にKiを加算。
    if k <= K:
        return 1
    return 0


while (r - l > 1):  # O(logx)
    mid = (l + r) // 2
    if func(mid):
        r = mid
    else:
        l = mid


print(r)
# Original solution
import heapq
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
m = []
for i, j in zip(a, f):
    heapq.heappush(m, (-i*j, i, j))
for i in range(k):
    t = heapq.heappop(m)
    heapq.heappush(m, (-(t[1] - 1)*t[2], t[1]-1, t[2]))
    if m[0][0]== 0:
        print((0))
        break
else:
    print((-m[0][0]))



# Optimized solution
import math
def main():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    f = list(map(int, input().split()))
    a.sort(reverse=True)
    f.sort()
    hi = a[0] * f[-1]
    lo = 0
    def caneat(m):
        t = 0
        for i, j in zip(a, f):
            if i * j > m:
                t += math.ceil((i*j - m)/j)
            if t > k:
                return False
        return True
    while hi != lo:
        m = (hi + lo) // 2
        if caneat(m):
            hi = m
        else:
            lo = m + 1
    return hi
print((main()))
# Original solution
import heapq

N, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
T = [[- A[i] * F[i], A[i]] for i in range(N)]
heapq.heapify(T)

for _ in range(K):
    t, a = heapq.heappop(T)
    if t < 0:
        heapq.heappush(T, [(t // a) * (a - 1), a - 1])
    else:
        heapq.heappush(T, [0, 0])
        break

print((- heapq.heappop(T)[0]))


# Optimized solution
N, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)

minT, maxT = -1, max([A[i] * F[i] for i in range(N)])
while maxT - minT > 1:
    midT = minT + (maxT - minT) // 2
    if sum([max(A[i] - midT // F[i], 0) for i in range(N)]) > K:
        minT = midT
    else:
        maxT = midT

print(maxT)
# Original solution
def is_ok(x, A, F):
    trainings = 0
    for i in range(N):
        t = A[i] - x // F[i]
        if t > 0:
            trainings += t
    return trainings <= K


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

ng = -1
ok = A[-1] * F[0]
while ok - ng > 1:
    m = ng + (ok - ng) // 2
    if is_ok(m, A, F):
        ok = m
    else:
        ng = m
print(ok)


# Optimized solution
def is_ok(x):
    trainings = 0
    for i in range(N):
        t = A[i] - x // F[i]
        if t > 0:
            trainings += t
    return trainings <= K


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

ng = -1
ok = A[-1] * F[0]
while ok - ng > 1:
    m = ng + (ok - ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)
# Original solution
import sys
input=sys.stdin.readline
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
a=sorted(a)
f=list(map(int,input().split()))
f=sorted(f,reverse=True)

s=sum(a)
if k>=s:
    print((0))
    exit()

def is_ok(b):
    m=0
    for p,q in zip(a,f):
        if p>b//q:
            m+=p-(b//q)
            if m>k:
                return False
    return True

ok=10**12+1
ng=0
while ok-ng>1:
    m=(ok+ng)//2
    if is_ok(m):
        ok=m
    else:
        ng=m

print(ok)


# Optimized solution
import sys
input=sys.stdin.readline
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
a=sorted(a)
f=list(map(int,input().split()))
f=sorted(f,reverse=True)

def is_ok(b):
    m=0
    for p,q in zip(a,f):
        if p>b//q:
            m+=p-(b//q)
            if m>k:
                return False
    return True

ok=10**12+1
ng=-1
while ok-ng>1:
    m=(ok+ng)//2
    if is_ok(m):
        ok=m
    else:
        ng=m

print(ok)
# Original solution
from heapq import *
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
F = list(map(int, input().split()))
F.sort(reverse=True)
data = []
for a, f in zip(A, F):
    heappush(data, (-a*f, a, f))
for _ in range(K):
    x, a, f = heappop(data)
    if a > 0:
        a -= 1
    heappush(data, (-a*f, a, f))

print((-heappop(data)[0]))

# Optimized solution
import sys
input = sys.stdin.readline

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
F = list(map(int, input().split()))
F.sort(reverse=True)

def max2(x,y):
    return x if x > y else y

def test(x):
    temp = K
    for a, f in zip(A, F):
        temp -= max2((a - x//f), 0)
        if temp < 0:
            return False
    return True

print((binary_search_int(A[-1]**2 + 100, -1,test)))
# Original solution
import heapq 
N, K = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])
F = sorted([int(x) for x in input().split()], reverse=True)
h = []
if (sum(A) <= K):
    print((0))
else:
    for a, f in zip(A, F):
        heapq.heappush(h, (-a*f, [a, f]))
    for i in range(K):
        before = heapq.heappop(h)
        a, f = before[1]
        heapq.heappush(h, (-(a-1)*f, [a-1, f]))
    print((-1 * heapq.heappop(h)[0]))


# Optimized solution
N, K = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])
F = sorted([int(x) for x in input().split()], reverse=True)
lb = 0
ub = 10 ** 12
def isPossible(M):
    cnt = 0
    # a = 4 , f = 5 のとき a*f = 20
    # M = 30 => そのままでOK
    # M = 9 => (20-9+4)//5
    for a, f in zip(A, F):
        if (M >= a*f): continue
        cnt += (a*f - M + (f-1)) // f
    return cnt <= K

for i in range(100):
    mid = (lb + ub) // 2
    if (isPossible(mid)):
        ub = mid
    else:
        lb = mid
print(ub)
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse = True)

import heapq
pop = heapq.heappop
push = heapq.heappush
q  = []

for i in range(N):
  push(q, [- A[i] * F[i], A[i], F[i]])

for i in range(K):
  x, y, z = pop(q)
  if y == 0:
    print((0))
    exit()
  push(q, [- (y - 1) * z, y - 1, z])

t = pop(q)
print((-t[0]))

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse = True)

M = 0
for i in range(N):
  M += A[i] * F[i]

def nasu(n):
  ans = 0
  for i in range(N):
    ans += max(0, A[i] - (n // F[i]))
  if ans <= K:
    return True
  else:
    return False

def hersCode():
  ok = M
  ng = -1
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if nasu(mid):
      ok = mid
    else:
      ng = mid
  return ok

print((hersCode()))
# Original solution
n,k=list(map(int,input().split()))
a=list(map(int, input().split()))
f=list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

maxaf=a[0]*f[0]
for i in range(n):
	if a[i]*f[i]>maxaf:
		maxaf=a[i]*f[i]

def solve(x):
	total=0
	for i in range(n):
		total+=max(0,a[i]-x//f[i])
	return total<=k

#xの範囲 ngは実現が難しい方
ok=maxaf
ng=-1

while ok-ng>1:
	mid=(ok+ng)//2
	if solve(mid):
		ok=mid
	else:
		ng=mid
print(ok)

# Optimized solution
n,k=list(map(int,input().split()))
a=list(map(int, input().split()))
f=list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

maxaf=a[0]*f[0]
for i in range(n):
	if a[i]*f[i]>maxaf:
		maxaf=a[i]*f[i]

def solve(x):
	total=0
	for i in range(n):
		total+=max(0,a[i]-x//f[i]) #負になりうる懸念ができていなかった、とほほ
	return total<=k

#xの範囲 ngは実現が難しい方
ok=maxaf
ng=-1

while ok-ng>1:
	mid=(ok+ng)//2
	if solve(mid):
		ok=mid
	else:
		ng=mid
print(ok)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort()
f.sort()
f = f[::-1]

import heapq
af = []
heapq.heapify(af)
for i in range(len(a)):
    heapq.heappush(af, [a[i] * f[i] * -1, f[i]])

for i in range(k):
    tmp = heapq.heappop(af)
    tmp[0] = (tmp[0] // tmp[1] + 1) * tmp[1]
    heapq.heappush(af, tmp)

print((max(heapq.heappop(af)[0] * -1, 0)))


# Optimized solution
n, k = list(map(int, input().split()))
aa = list(map(int, input().split()))
ff = list(map(int, input().split()))

a = sorted(aa, reverse=True)
f = sorted(ff)

def C(x):
    ret = 0
    for i in range(n):
        ret += max(0, a[i] - x // f[i])
    return ret

lb = -1
ub = 10 ** 12 + 1
while (ub - lb) > 1:
    mid = (ub + lb) // 2

    if C(mid) > k:
        lb = mid
    else:
        ub = mid
print(ub)
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

start = -1
end = A[-1] * F[0]

def check(now):
    cnt = 0
    for i in range(N):
        if A[i] * F[i] > now:
            cnt += (A[i]*F[i] - now + F[i] - 1) // F[i]
    if cnt > K:
        return False
    return True

while end > start + 1:
    now = (start + end) // 2
    if check(now):
        end = now
    else:
        start = now

print(end)


# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

start = -1
end = A[-1] * F[0]

def check(now):
    cnt = 0
    for a, f in zip(A, F):
        eatable = now//f
        if eatable < a:
            cnt += a - eatable
    if cnt > K:
        return False
    return True

while end > start + 1:
    now = (start + end) // 2
    if check(now):
        end = now
    else:
        start = now

print(end)
# Original solution
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
F=list(map(int,input().split()))

A.sort()
F.sort(reverse=True)

def condition(num):
    count=0
    goal=[num//F[i] for i in range(N)]
    for i in range(0,N):
        if A[i]>goal[i]:
            count+=A[i]-goal[i]
    return K>=count

start=0
end=10**20
while end-start>1:
    test=(end+start)//2
    if condition(test):
        end=test
    else:
        start=test

if condition(start):
    print(start)
else:
    print(end)

# Optimized solution
import sys

input=sys.stdin.readline

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
F=list(map(int,input().split()))

A.sort()
F.sort(reverse=True)

def condition(num):
    count=0
    goal=[num//F[i] for i in range(N)]
    for i in range(0,N):
        if A[i]>goal[i]:
            count+=A[i]-goal[i]
    return K>=count

start=0
end=2*(10**17)
while end-start>1:
    test=(end+start)//2
    if condition(test):
        end=test
    else:
        start=test

if condition(start):
    print(start)
else:
    print(end)
# Original solution
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def meguru_bisect(is_ok, left, right):
        """
        :param is_ok: 定義して下さい
        :param left: 取りうる最小の値-1
        :param right: 取りうる最大の値+1
        :return: is_okを満たす最小(もしくは最大)の値
        """
        while abs(left - right) > 1:
            mid = (left + right) // 2
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    def is_ok(x):
        total = 0
        for i in range(n):
            total += max(0, A[i] - x // F[i])
        return total <= k

    n, k = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())))
    F = sorted(list(map(int, input().split())), reverse=True)

    left = -1
    right = 10 ** 12 + 1
    res = meguru_bisect(is_ok, left, right)
    print(res)


if __name__ == '__main__':
    resolve()


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def meguru_bisect(left, right):
        """
        is_okを定義して下さい
        :param left: 取りうる最小の値-1
        :param right: 取りうる最大の値+1
        :return: is_okを満たす最小(もしくは最大)の値
        """
        while abs(left - right) > 1:
            mid = (left + right) // 2
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    def is_ok(x):
        total = 0
        for i in range(n):
            total += max(0, A[i] - x // F[i])
        return total <= k

    n, k = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())))
    F = sorted(list(map(int, input().split())), reverse=True)

    left = -1
    right = 10 ** 12 + 1
    res = meguru_bisect(left, right)
    print(res)


if __name__ == '__main__':
    resolve()
# Original solution
import math

#成績xを取れるか？xに関して二分探索

N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
F = list(map(int,input().split()))

#Aを小さい順，Fを大きい順に並べれば対応する．
A.sort()
F.sort(reverse =True)
AF=[0]*N

for i in range(N):
    AF[i]=A[i]*F[i]
    
ng=-1
ok=10**12+1

#二分探索，成績xをとるのにi番目の人が何回修行すべきか，これがK以下なら良い
while ok-ng!=1:
    x = (ok+ng)//2
    num_tra =0
    for i in range(N):
        af_i = int(math.ceil((AF[i]-x)/F[i]))
        if af_i>0:
            num_tra+=af_i
    if num_tra<=K:
        ok=x
    else:
        ng=x
        
print(ok)

# Optimized solution
import sys
input = sys.stdin.readline

def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))


"""
コストが低い人が食べにくいものを食べる．
コストが低い人を追い抜かすことはない，（追い抜かすなら入れ替えて良いから）


"""
def main():
    mod=10**9+7
    N,K=MI()
    A=LI()
    F=LI()
    F.sort()
    A.sort(reverse=True)
    
    if K>=sum(A):
        print((0))
        exit()
        
    def ch(x):
        # x秒でクリアできるか
        temp=0#　必要修行回数
        for i in range(N):
            af=A[i]*F[i]
            if af>x:
                add=(af-x+F[i]-1)//F[i]
                temp+=(add)
                
        return temp <= K
        
    ok=10**12
    ng=0
    
    while ok-ng>1:
        med=(ok+ng)//2
        if ch(med):
            ok=med
        else:
            ng=med 
            
    print(ok)
    
main()
# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = sorted(LI())
F = sorted(LI(), reverse=True)


que = [(-A[i] * F[i], -F[i], A[i]) for i in range(n)]
heapify(que)
while k and que:
    x, f, a = heappop(que)
    if a:
        a -= 1
        x -= f
        heappush(que, (x, f, a))
        k -= 1




if que:
    print((-que[0][0]))
else:
    print((0))


# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = sorted(LI())
F = sorted(LI(), reverse=True)
ok = A[-1] * F[0]
ng = -1
while ok > ng + 1:
    mid = (ok + ng) // 2
    ret = 0
    for i in range(n):
        if A[i] * F[i] > mid:
            ret += (A[i] * F[i] - mid) // F[i] + bool((A[i] * F[i] - mid) % F[i])
    if ret > k:
        ng = mid
    else:
        ok = mid


print(ok)
# Original solution
import heapq

N,K = list(map(int, input().split()))
A = [int(a) for a in input().split()]
F = [int(f) for f in input().split()]

    
if K >= sum(A):
    ans = 0
else:
    A.sort(reverse=True)
    F.sort()
    h = []
    for i in range(N):
        heapq.heappush(h, [-A[i]*F[i], A[i], F[i]])
    while K > 0:
        temp = heapq.heappop(h)
        temp[0] += temp[2]
        temp[1] -= 1
        heapq.heappush(h, temp)
        K -= 1
    L = heapq.heappop(h)
    ans = -L[0]
print(ans)

# Optimized solution
N,K = list(map(int, input().split()))
A = [int(a) for a in input().split()]
F = [int(f) for f in input().split()]

A.sort()
F.sort(reverse=True)

if K >= sum(A):
    ans = 0
else:
    u = 10**13
    l = 0
    while u-l > 1:
        x = (u+l)//2
        cnt = K
        for i in range(N):
            cnt -= max(0, A[i]-x//F[i])
        if cnt >= 0:
            u = x
        else:
            l = x
    cnt = K
    for i in range(N):
        cnt -= max(0, A[i]-l//F[i])
    if cnt >= 0:
        ans = l
    else:
        ans = u
        
print(ans)