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 = sorted(A)
F = sorted(F, reverse=True)
mul = [A[i]*F[i] for i in range(N)]

if K >= sum(A)*N:
    print((0))
    exit()

ma = 2**40
mi = 0
while 1:
    tgt = mi + (ma - mi)//2
    num = 0
    for i in range(N):
        tmp = (mul[i] - tgt + F[i] - 1) // F[i]
        if tmp < 0:
            tmp = 0
        num += tmp
    if ma == mi:
        print(ma)
        exit()
    if num <= K:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2+1

# Optimized solution
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, reverse=True)
mul = [A[i]*F[i] for i in range(N)]

if K >= sum(A):
    print((0))
    exit()

ma = 2**40
mi = 0
while 1:
    tgt = mi + (ma - mi)//2
    num = 0
    for i in range(N):
        tmp = (mul[i] - tgt + F[i] - 1) // F[i]
        if tmp <= 0:
            continue
        num += tmp
    if ma == mi:
        print(ma)
        exit()
    if num <= K:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2+1
# Original solution
import sys
from io import StringIO
import unittest
import math


def check(A, F, x, N, K):
    for i in range(N):
        if A[i] * F[i] > x:
            k = math.ceil(A[i] - x / F[i])
            K -= k
    if K < 0:
        return False
    else:
        return True


def resolve():
    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()

    # binary search
    l = 0
    r = max(A) * max(F)
    result = None
    while l <= r:
        # print('l {}, r {}'.format(l, r))
        if l == r:
            result = l
            break
        mid = (l + r) // 2
        if check(A, F, mid, N, K):
            r = mid
        else:
            l = mid + 1

    print(result)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 5
4 2 1
2 3 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 8
4 2 1
2 3 1"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2"""
        output = """12"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


# Optimized solution
import math


def check(A, F, x, N, K):
    for i in range(N):
        if A[i] * F[i] > x:
            k = math.ceil(A[i] - x / F[i])
            K -= k
    if K < 0:
        return False
    else:
        return True


def resolve():
    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()

    # binary search
    l = 0
    r = max(A) * max(F)
    result = None
    while l <= r:
        # print('l {}, r {}'.format(l, r))
        if l == r:
            result = l
            break
        mid = (l + r) // 2
        if check(A, F, mid, N, K):
            r = mid
        else:
            l = mid + 1

    print(result)


if __name__ == "__main__":
    resolve()
# 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()

pq = []
for i in range(n):
    heapq.heappush(pq, (-a[i]*f[i], a[i], f[i]))

for i in range(k):
    score, ai, fi = heapq.heappop(pq)
    if score == 0:
        heapq.heappush(pq, (0, 0, 0))
        break
    heapq.heappush(pq, (-((ai-1) * fi), ai-1, fi))

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


# Optimized solution
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()

ori = [0] * n
for i in range(n):
    ori[i] = a[i]*f[i]

ok = max(ori)
ng = -1
mid = (ok+ng) // 2
while ok - ng > 1:
    cnt = 0
    flg = 0
    for i in range(n):
        if ori[i] > mid:
            cnt += (a[i] - mid // f[i])
        if cnt > k:
            flg = 1
            break
    if flg:
        ng = mid
    else:
        ok = mid
    mid = (ok + ng) // 2

print(ok)
# Original solution
import sys
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(eval(input()))
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,K=LI()
As=LI()
As.sort()
Fs=LI()
Fs.sort(reverse=True)

HQ=[]

for i in range(N):
    heapq.heappush(HQ, (-As[i]*Fs[i], As[i], Fs[i]))

# print(HQ)
while K:
    score,A,F=heapq.heappop(HQ)
    if HQ:
        score2,A2,F2=HQ[0]
        diff = min((score2 - score) // F + 1, K)

        heapq.heappush(HQ, (-(A-diff)*F , A-diff, F))
        K = K - diff
    else:
        print((max(A-K,0)*F))
        exit()

ans, _, _ =heapq.heappop(HQ)
print((-ans))


# Optimized solution
import sys
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(eval(input()))
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,K=LI()
As=LI()
As.sort()
Fs=LI()
Fs.sort(reverse=True)

rgt = 10**12
lft = 0
while lft < rgt:
    cost = K
    half = (lft + rgt) // 2
    for i in range(N):
        if As[i]*Fs[i] > half:
            cost -= (As[i]*Fs[i] - half) // Fs[i]
            cost -= 1 if (half - As[i]*Fs[i]) % Fs[i] > 0 else 0

    if cost < 0:
        lft = half + 1
    else:
        rgt = half
    # print(lft, rgt)

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

def isEaten(x):
    temp = 0
    for i in range(N):
        t = x // F[i]
        if t < A[i]:
            temp += (A[i] - t)
    if temp > K:
        return False
    else:
        return True


def bitSearch(r, l):
    m = (r+l) // 2
    if m == l:
        if isEaten(l):
            print(l)
        else:
            print(r)
        exit()
    elif isEaten(m):
        bitSearch(m, l)
    else:
        bitSearch(r, m)


target = max([A[i]*F[i] for i in range(N)])
bitSearch(target, 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)
 
def isEaten(x):
    temp = 0
    for i in range(N):
        t = x // F[i]
        if t < A[i]:
            temp += (A[i] - t)
    return temp <= K
 
 
def bitSearch(r, l):
    m = (r+l) // 2
    if m == l:
        if isEaten(l):
            print(l)
        else:
            print(r)
        exit()
    elif isEaten(m):
        bitSearch(m, l)
    else:
        bitSearch(r, m)
 
 
target = max([A[i]*F[i] for i in range(N)])
bitSearch(target, 0)
# Original solution
import sys
import heapq


def main():
    n, k = [int(s) for s in sys.stdin.readline().strip().split()]
    a = [int(s) for s in sys.stdin.readline().strip().split()]
    f = [int(s) for s in sys.stdin.readline().strip().split()]
    # n, k = 3, 5
    # a = [4, 2,1]
    # f = [2, 3, 1]

    a.sort(reverse=True)
    f.sort()

    heap = []
    for i in range(n):
        ai = a[i]
        fi = f[i]
        heap.append((- ai * fi, ai, fi))
    heapq.heapify(heap)

    for i in range(k):
        prod, ai, fi = heapq.heappop(heap)
        if prod == 0:
            break
        new_prod = - (ai - 1) * fi
        heapq.heappush(heap, (new_prod, ai-1, fi))

    print((- heap[0][0]))


main()



# Optimized solution
import sys
import heapq


def main():
    n, k = [int(s) for s in sys.stdin.readline().strip().split()]
    a = [int(s) for s in sys.stdin.readline().strip().split()]
    f = [int(s) for s in sys.stdin.readline().strip().split()]
    # n, k = 3, 5
    # a = [4, 2,1]
    # f = [2, 3, 1]

    a.sort(reverse=True)
    f.sort()

    def possible(x1):
        improved = 0
        for i in range(n):
            before = a[i] * f[i]
            if before > x1:
                needed_to_be_reduced = before - x1
                if needed_to_be_reduced % f[i] == 0:
                    plus_one = 0
                else:
                    plus_one = 1
                improved += (needed_to_be_reduced // f[i]) + plus_one
                if improved > k:
                    return False
        return True

    def b_search():
        lo = 0
        hi = 10 ** 12
        # (lo, hi]
        # hi is always possible
        # lo might be possible

        while lo < hi:
            mid = (lo + hi) // 2
            if possible(mid):
                hi = mid
            else:
                lo = mid+1
        return hi

    ans = b_search()
    print(ans)


main()
# Original solution
import math
N, K = list(map(int, input().split()))
As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))[::-1]
Cs = [a*b for a, b in zip(As, Bs)]
BCs = list(zip(Bs, Cs))

def func(target):
    r = 0
    for b, c in BCs:
        r += math.ceil(max(0, c - target) / b)
    return r <= K

if __name__ == '__main__':
    min_i, max_i, index = -1, max(Cs)+1, 1
    while True:
        if func(index):
            index, max_i = (index-1 + min_i)//2, index-1
            continue
        index, min_i = (index+1 + max_i)//2, index+1
        if min_i > max_i:
            print(min_i)
            break

# Optimized solution
import math
N, K = list(map(int, input().split()))
As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))[::-1]
Cs = [a*b for a, b in zip(As, Bs)]
BCs = list(zip(Bs, Cs))

def func(target):
    r = 0
    for b, c in BCs:
        r += math.ceil(max(0, c - target) / b)
    return r <= K

if __name__ == '__main__':
    min_i, max_i, index = 0, max(Cs)+1, 1
    while True:
        if func(index):
            index, max_i = (index-1 + min_i)//2, index-1
        else:
            index, min_i = (index+1 + max_i)//2, index+1
        if min_i > max_i:
            print(min_i)
            break
# Original solution
import math
N,K=list(map(int,input().split()))
X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])]
m,M,i=0,10**12,1
exec("i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);"*50)
print(M)

# Optimized solution
N,K=list(map(int,input().split()))
X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])]
m,M,i=0,2**40,1
exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-c)//b for b, c in X)<=K else((i+M)//2,M,i);"*50)
print(M)
# Original solution
(_,K),*T=[list(map(int,t.split()))for t in open(0)]
A,B=list(map(sorted,T))
m,M,i=0,2**40,1
exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K else((i+M)//2,M,i);"*41)
print(M)

# Optimized solution
(_,K),*T=[list(map(int,t.split()))for t in open(0)]
A,B=list(map(sorted,T))
d=[0,2**40]
exec("i=sum(d)//2;d[-sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K]=i;"*41)
print((d[1]))
# Original solution
import heapq as hq
N, K = list(map(int, input().split()))
A = list(map(int,input().split()))
A.sort()
F = list(map(int,input().split()))
F.sort()
q = [(-A[i]*F[N-1-i], F[N-1-i]) for i in range(N)]
hq.heapify(q)
cnt = 0
while cnt < K:
	cnt += 1
	c = hq.heappop(q)
	if c[0] < 0:
		hq.heappush(q, (c[0]+c[1], c[1]))
	else:
		hq.heappush(q, c)
		break
print((-hq.heappop(q)[0]))

# Optimized solution
import heapq as hq
N, K = list(map(int, input().split()))
A = list(map(int,input().split()))
A.sort()
F = list(map(int,input().split()))
F.sort()

if sum(A) <= K:
	print((0))
	exit()
ans = max([A[i]*F[N-1-i] for i in range(N)])

def achievable(score):
	cnt = 0
	for i in range(N):
		a,f = A[i], F[N-1-i]
		if a*f > score:
			n = score // f
			cnt += a-n
			if cnt > K:
				return False
	return True

l,r = 0, ans
while r - l > 1:
	p = (l + r) // 2
	if achievable(p):
		r = p
	else:
		l = p
print(r)
# Original solution
import sys
input = sys.stdin.readline
import math
def solve():
  n,k = (int(i) for i in input().split())
  a = sorted(list(int(i) for i in input().split()))
  f = sorted(list(int(i) for i in input().split()),reverse = True)
  if sum(a) <= k:
    print((0))
    exit()
  
  ng = 0
  ok = 10**15

  while ok-ng >1 :
    next = (ok+ng)//2
    #a*fの値がnext以下になるか判定する
    tmpk = k
    for i in range(n):
      ta = a[i]
      tf = f[i]
      if ta*tf > next:
        tmpk -= math.ceil((ta*tf-next)/tf)
    if tmpk < 0:
       ng = next
    else:
       ok = next
  print(ok)
    
solve()

# Optimized solution
import sys
input = sys.stdin.readline
import math
def solve():
  n,k = (int(i) for i in input().split())
  a = sorted(list(int(i) for i in input().split()))
  f = sorted(list(int(i) for i in input().split()),reverse = True)
  if sum(a) <= k:
    print((0))
    exit()
  
  ng = 0
  ok = 10**12

  while ok-ng >1 :
    next = (ok+ng)//2
    #a*fの値がnext以下になるか判定する
    tmpk = k
    for i in range(n):
      ta = a[i]
      tf = f[i]
      if ta*tf > next:
        tmpk -= math.ceil((ta*tf-next)/tf)

    if tmpk < 0:
       ng = next
    else:
       ok = next
  print(ok)
    
solve()
# Original solution
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(eval(input()))

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))
AF = [A[i]*F[i] for i in range(N)]

afmax = max(AF)

def can(max_af):
  k = K
  for i in range(N):
    af = AF[i]
    if af>max_af:
      max_ai = max_af // F[i]
      k -= A[i]-max_ai
      if k<0:
        return False
  return k>=0

l = -1
r = afmax
while r-l>1:
  m = (l+r)//2
  if can(m):
    r = m
  else:
    l = m
print(r)



# Optimized solution
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(eval(input()))

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))
AF = [A[i]*F[i] for i in range(N)]

afmax = max(AF)

def can(seiseki):
  k = K
  for i in range(N):
    af = AF[i]
    if af>seiseki:
      k -= math.ceil((af-seiseki)/F[i])
      if k<0:
        return False
  return k>=0

l = -1
r = afmax
while r-l>1:
  m = (l+r)//2
  if can(m):
    r = m
  else:
    l = m
print(r)
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *AF = list(map(int, read().split()))
    A = AF[:N]
    F = AF[N:]

    A.sort()
    F.sort(reverse=True)
    C = [a * f for a, f in zip(A, F)]

    def is_ok(cost):
        k = 0
        for c, f in zip(C, F):
            if c > cost:
                k += (c - cost + f - 1) // f
        return k <= K

    ok = max(C)
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid

    print(ok)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *AF = list(map(int, read().split()))
    A = AF[:N]
    F = AF[N:]

    A.sort()
    F.sort(reverse=True)
    C = [a * f for a, f in zip(A, F)]

    def is_ok(cost):
        k = 0
        for i in range(N):
            if C[i] > cost:
                k += (C[i] - cost + F[i] - 1) // F[i]
        return k <= K

    ok = max(C)
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid

    print(ok)
    return


if __name__ == '__main__':
    main()
# Original solution
n,k=list(map(int,input().split()))
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort()

def chk(x):
  ct=0
  for i in range(n):
    a,f=A[i],F[-i-1]
    ct+=max(0,a-x//f)
  if ct<=k:
    return True
  else:
    return False


l,r=0,A[-1]*F[-1]
while r-l>1:
  m=(l+r)//2
  if chk(m):
    r=m
  else:
    l=m

if chk(l):
  print(l)
else:
  print(r)

# Optimized solution
n,k=list(map(int,input().split()))
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort()

def chk(x):
  ct=0
  for i in range(n):
    a,f=A[i],F[-i-1]
    ct+=max(0,a-x//f)
    if ct>k:
      return False
  if ct<=k:
    return True
  else:
    return False
l=0
r=0
for i in range(n):
  r=max(r,A[i]*F[-i-1])

while r-l>1:
  m=(l+r)//2
  if chk(m):
    r=m
  else:
    l=m

if chk(l):
  print(l)
else:
  print(r)
# Original solution
n,k=list(map(int,input().split()))
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort()

def chk(x):
  ct=0
  for i in range(n):
    a,f=A[i],F[-i-1]
    ct+=max(0,a-x//f)
    if ct>k:
      return False
  if ct<=k:
    return True
  else:
    return False
l=0
r=0
for i in range(n):
  r=max(r,A[i]*F[-i-1])

while r-l>1:
  m=(l+r)//2
  if chk(m):
    r=m
  else:
    l=m

if chk(l):
  print(l)
else:
  print(r)


# Optimized solution
n,k=list(map(int,input().split()))
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort()

def chk(x):
  ct=0
  for i in range(n):
    a,f=A[i],F[-i-1]
    ct+=max(0,a-x//f)
  if ct<=k:
    return True
  else:
    return False


l,r=0,A[-1]*F[-1]
while r-l>1:
  m=(l+r)//2
  if chk(m):
    r=m
  else:
    l=m

if chk(l):
  print(l)
else:
  print(r)
# Original solution
import bisect
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)

for ans in range(a[-1] * f[-1] + 1):
    tmp = 0
    for x, y in zip(a,f):
        tmp += x - math.floor(ans / y)
    if tmp <= k:
        break
print(ans)

# Optimized solution
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)

low = 0
high = 0
for x, y in zip(a,f):
    high = max(high, x*y)

while high != low:
    test = int((high + low) // 2)
    tmp = 0
    for x, y in zip(a,f):
        tmp += max(0, x - math.floor(test / y))
        if tmp > k:
            low = test + 1
            break
    else:
        high = test
print(high)
# Original solution
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)

low = 0
high = 0
for x, y in zip(a,f):
    high = max(high, x*y)

while high != low:
    test = int((high + low) // 2)
    tmp = 0
    for x, y in zip(a,f):
        tmp += max(0, x - math.floor(test / y))
        if tmp > k:
            low = test + 1
            break
    else:
        high = test
print(high)

# Optimized solution
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort(reverse=True)
f.sort()

low = 0
high = 0
for x, y in zip(a,f):
    high = max(high, x*y)

while high != low:
    test = int((high + low) // 2)
    tmp = 0
    for x, y in zip(a,f):
        tmp += max(0, x - int(test / y))
        if tmp > k:
            low = test + 1
            break
    else:
        high = test
print(high)
# Original solution
import bisect
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, reverse=True)

score = sorted(((x * y, x, y) for (x, y) in zip(a, f)))
for _ in range(k):
    p, x, y = score.pop()
    if x > 0:
        x -= 1
    bisect.insort(score, (x * y, x, y))

p, _, _ = score.pop()
print(p)



# Optimized solution
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, reverse=True)

def judge(n):
    s = 0
    for x, y in zip(a, f):
        s += max(0, x - n // y)
    if s <= k:
        return True
    else:
        return False

low = 0
high = a[-1] * f[0]
while high - low > 0:
    mid = (high + low) // 2
    if judge(mid):
        high = mid
    else:
        low = mid + 1
print(high)
# Original solution
import math

n,k=list(map(int,input().split()))
a=sorted([int(i) for i in input().split()],reverse=True)
f=sorted([int(i) for i in input().split()])
c=[[a[i],f[i]] for i in range(n)]
c.sort(key=lambda x:x[0]*x[1],reverse=True)

if n==1:
    print((max(0,(c[0][0]-k)*c[0][1])))
else:
    while True:
        #print(c)
        if k==0 or c[0][0]==0:
            break
        elif c[0][0]*c[0][1]-c[1][0]*c[1][1]==0:
            k-=1
            c[0][0]-=1
        elif c[0][0]*c[0][1]-c[1][0]*c[1][1] < c[0][1]:
            k-=1
            c[0][0]-=1
        else:
            l=math.ceil((c[0][0]*c[0][1]-c[1][0]*c[1][1])/c[0][1])
            m=min(l,c[0][0])
            k-=m
            c[0][0]-=m
        for i in range(n-1):
            if c[i][0]*c[i][1]<=c[i+1][0]*c[i+1][1]:
                c[i],c[i+1]=c[i+1],c[i]
            else:
                break

    #print(c)
    print((c[0][0]*c[0][1]))


# 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)
l,r=0,10**12
def cal(x):
    global n,f,a,k
    ret=0
    for i in range(n):
        ret+=max(0,a[i]-(x//f[i]))
    #print(ret,x)
    return ret
while l+1<r:
    x=l+(r-l)//2
    if cal(x)<=k:
        r=x
    else:
        l=x
if cal(l)<=k:
    print(l)
else:
    print(r)
# Original solution
import bisect
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    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)

    B=[]
    for i in range(N):
        B.append((A[i]*F[i],F[i]))

    B.sort()
    for _ in range(K):
        if not len(B) > 0:
            break
        b,f = B.pop()
        front = (b-f,f)

        if b-f > 0:
            bisect.insort(B,front)

    print((max(B)[0] if len(B) > 0 else 0))
    # print(B)



if __name__ == "__main__":
  main()

# Optimized solution
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    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 c(s): # sに対して単調減少
        sum_x = 0
        for i in range(N):
            a,f=A[i],F[i]
            tp = s//f
            if not a <= tp:
                sum_x += a-tp

        return sum_x <= K

    l=-1
    r=10**20
    while r-l>1:
        mid = (l+r)//2
        if c(mid):
            r = mid
        else:
            l = mid

    print(r)

if __name__ == "__main__":
  main()