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()))
if K >= sum(A):
  print((0))
  exit()
A.sort(reverse=True)
F.sort()

#print('A:', A)
#print('F:', F)


res = K

lot = [A[k]*F[k] for k in range(N)]
#print(lot)
#print(res)

now = []
for k in range(N):
  now.append((-lot[k], k))
from heapq import heapify, heappop, heappush
from math import ceil
heapify(now)
#print(now)
f = heappop(now)
while res>0:
  #print(res)
  #print(now)
  s = heappop(now)
  big = lot[f[1]]
  small = lot[s[1]]
  cnt = ceil((big-small)/F[f[1]])
  if big == small:
    cnt = 1
  if cnt > A[f[1]]:
    print((lot[f[1]] - A[f[1]]*F[f[1]]))
    exit()
  if cnt >= res:
    lot[f[1]] -= res*F[f[1]]
    break
  else:
    lot[f[1]] -= cnt*F[f[1]]
    A[f[1]] -= cnt
    res -= cnt
    heappush(now, (-lot[f[1]], f[1]))
  f = s
  
print((max(lot)))

# Optimized solution
from math import ceil
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print((0))
  exit()
A.sort(reverse=True)
F.sort()
lot = []
for k in range(N):
  lot.append((A[k]*F[k], k))
lot.sort(key =  lambda x:x[0],reverse=True)
high = lot[0][0]
#print('A:', A)
#print('F:', F)
#rint(lot)
def binary_search(high):
  low = 0
  mid = (low + high) //2
  while low < high:
    final = False
    mid = (low + high) //2
    #print(low, high, mid)
    if low == high-1:
      final = True
    #print(low, high, mid)
    res = K
    flag = True
    for k in range(N):
      if res < 0:
        break
      else:
        if lot[k][0] <= mid:
          break
        else:
          res -= ceil((lot[k][0]-mid)/F[lot[k][1]])
          continue
    if res < 0:
      flag = False
    #print(flag)
    if flag:
      high = mid
    else:
      if final:
        mid += 1
      low = mid
    #print(low, high, mid)
  #return None
  return mid

print((binary_search(high)))
# Original solution
import math
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())

def judge(x):
  cnt = 0
  for i in range(N):
    tmp = a[i] - x//f[i]
    cnt += max(tmp, 0)
  else:
    if cnt <= K:
      return True
    else:
      return False

# 二分探索 #
def nibutan(): # MAX(A*F) ans
    left = -1
    ans = num
    while left+1 != ans:
        middle = (left+ans)//2
        if judge(middle):
            ans = middle
        else:
            left = middle
    return ans

N, K = IL()
a = IL()
f = IL()
a.sort()
f.sort(reverse=True)
num = 0
for i in range(N):
  num = max(num, a[i]*f[i])

print((nibutan()))


# Optimized solution
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())

def judge(x):
  cnt = 0
  for i in range(N):
    tmp = a[i] - x//f[i]
    cnt += max(tmp, 0)
  else:
    if cnt <= K:
      return True
    else:
      return False

# 二分探索 #
def nibutan(): # MAX(A*F) ans
    left = -1
    ans = num
    while left+1 != ans:
        middle = (left+ans)//2
        if judge(middle):
            ans = middle
        else:
            left = middle
    return ans

N, K = IL()
a = IL()
f = IL()
a.sort()
f.sort(reverse=True)
num = 0
for i in range(N):
  num = max(num, a[i]*f[i])

print((nibutan()))
# Original solution
import math
N,K = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
F = sorted(list(map(int,input().split())),reverse=True)
high = 0
for i in range(N):
    high = max(high,A[i]*F[i])
low = -1
while high-low>1:
    mid = (high+low)//2
    flag = 1
    T = K
    for i in range(N):
        if A[i]*F[i]<=mid:continue
        else:
            T -= math.ceil(A[i]-mid/F[i])
            if T<0:
                flag = 0
                break
    if flag==1:
        high = mid
    else:
        low = mid
print(high)

# 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)
if K>=sum(A):
    ans = 0
else:
    low = 0
    high = 10**12
    while high-low>1:
        mid = (high+low)//2
        B = A[:]
        cnt = 0
        for i in range(N):
            if B[i]*F[i]>mid:
                cnt += (B[i]-mid//F[i])
        if cnt<=K:
            high = mid
        else:
            low = mid
    ans = high
print(ans)
# Original solution
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=1)
	prod = [(y, x * y) for x, y in zip(a, f)]
	l = -1
	r = 10 ** 12
	while r - l > 1:
		m = (l + r) // 2
		s = sum(max(0, 0 - (m - p) // y) for y, p in prod)
		if s <= k:
			r = m
		else:
			l = m
	print(r)


if __name__ == "__main__":
	main()

# Optimized solution
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)
	prod = sorted([(x * y, y) for x, y in zip(a, f)], reverse=True) + [(0, -1)]
	l = -1
	r = 10 ** 12
	while r - l > 1:
		m = (l + r) // 2
		s = 0
		for p, y in prod:
			if p <= m:
				r = m
				break
			s += 0 - (m - p) // y
			if s > k:
				l = m
				break
	print(r)


if __name__ == "__main__":
	main()
# Original solution
import math
n, k = list(map(int, input().split()))
# a = [int(x) for x in input().split()]
# f = [int(x) for x in input().split()]
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
lx = 0
rx = a[-1] * f[0]
for i in range(1000):
    if lx == rx:
        break
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        ta = a[j]
        y = (ta*f[j] - cx + f[j] -1) // f[j]
        kk += max(0, y)
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)

# Optimized solution
n, k = list(map(int, input().split()))
# a = [int(x) for x in input().split()]
# f = [int(x) for x in input().split()]
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
lx = -1
rx = a[-1] * f[0]
while rx-lx>1 :
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        kk += max(0, a[j] - cx//f[j])
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)
# Original solution
import copy
import math
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort()
A.reverse()
maxX = max(F) * max(A)
x = [-1 for i in range(maxX + 1)]
def is_able(low, up):
    target = (low + up) // 2
    if low == up - 1:
        return up
    if check(target):
        x[target] = 1
        return is_able(low, target)
    else:
        x[target] = 0
        return is_able(target, up)

def check(time):
    #time が可能かどうか
    practice = copy.deepcopy(k)
    for i in range(n):
        if A[i] * F[i] > time:
            practice -= A[i] - math.floor(time / F[i]) 
            if practice < 0:
                return False
    return True
x[0] = int(check(0))
x[maxX] = int(check(maxX))
print((is_able(-1, maxX)))

# Optimized solution
import copy
import math
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort()
A.reverse()
maxX = max(F) * max(A)
def is_able(low, up):
    target = (low + up) // 2
    if low == up - 1:
        return up
    if check(target):
        return is_able(low, target)
    else:
        return is_able(target, up)
def check(time):
    #time が可能かどうか
    practice = copy.deepcopy(k)
    for i in range(n):
        if A[i] * F[i] > time:
            practice -= A[i] - math.floor(time / F[i]) 
            if practice < 0:
                return False
    return True
print((is_able(-1, maxX)))
# 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)
d=[[-a[i]*f[i],f[i]] for i in range(n)]
d.sort(key=lambda x:x[0])
heapq.heapify(d)
for _ in range(k):
  i,j=heapq.heappop(d)
  i+=j
  heapq.heappush(d,[i,j])
ans,_=heapq.heappop(d)
print((max(ans*(-1),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)
d=[[a[i]*f[i],f[i]] for i in range(n)]
r=max([di[0] for di in d])+1
l=0
x=(l+r)//2
while r-l>1:
  if r-l==2:
    cnt=0
    for di,fi in d:
      cnt+=max(0,(di-l+fi-1)//fi)
    if cnt<=k:
      x=l
    else:
      x=l+1
    break
  cnt=0
  for di,fi in d:
    cnt+=max(0,(di-x+fi-1)//fi)
  if cnt>k:
    l,r=x,r
  else:
    l,r=l,x+1
  x=(l+r)//2
if r-l==2:
  if cnt>k:
    x=l+1
  else:
    x=l

print(x)
# Original solution

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

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

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

def check(x):
  k = 0
  for a,f in zip(A, F):
    if a*f > x:
      while a > 0:
        a -= 1
        k += 1
        if a*f <= x: break

  return k <= K

# AをX以下にできるか？?
ng,ok = 0, 10**18+1
while ok-ng > 1:
  x = (ok+ng)//2
  if check(x):
    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()))

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

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

def check(x):
  k = 0
  for a,f in zip(A, F):
    k += max(0, a-(x//f))

  return k <= K

# AをX以下にできるか？?
ng,ok = 0, 10**18+1
while ok-ng > 1:
  x = (ok+ng)//2
  if check(x):
    ok = x
  else:
    ng = x

print(ok)
# Original solution
from heapq import heappush, heappushpop, heappop

N, K = list(map(int, input().split()))
A = list([-int(x) for x in input().split()])
F = list(map(int, input().split()))
A.sort()
F.sort()


hq = []
for a, f in zip(A, F):
    heappush(hq, (a * f, f))

c, f = heappop(hq)
while K > 0:
    c += f
    K -= 1
    c, f = heappushpop(hq, (c, f))

print((-c))


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

C = [None] * N
for i, (a, f) in enumerate(zip(A, F)):
    C[i] = (a * f, f)


def solve(x):
    global K, N
    t = 0
    for c, f in C:
        temp = ((c - x) + f - 1) // f
        t += max(0, temp)
        if t > K:
            result = False
            break
    else:
        result = True
    return result


ok = A[0] * F[N - 1]
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid


print(ok)
# Original solution
def solve(mid):
    l=k
    for b,g in zip(a,f):
        if b*g>mid:
            l-=b-mid//g
    if l<0:return False
    return True
n,k,*a=list(map(int,open(0).read().split()))
a,f=sorted(a[:n])[::-1],sorted(a[n:])
ok=10**12
ng=-1
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid):
        ok=mid
    else:
        ng=mid
print(ok)

# Optimized solution
def main():
    n,k,*a=list(map(int,open(0).read().split()))
    a,f=sorted(a[:n])[::-1],sorted(a[n:])
    ok=10**12
    ng=-1
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        l=k
        for b,g in zip(a,f):
            if b*g>mid:
                l-=b-mid//g
        if l<0:ng=mid
        else:ok=mid
    print(ok)
main()
# Original solution
def main():
    n,k,*a=list(map(int,open(0).read().split()))
    a,f=sorted(a[:n]),sorted(a[n:],reverse=1)
    ok=10**12
    ng=-1
    while ok-ng>1:
        mid=(ok+ng)//2
        l=k
        for b,g in zip(a,f):
            if b*g>mid:l-=b-mid//g
        if l<0:ng=mid
        else:ok=mid
    print(ok)
main()

# Optimized solution
def main():
    n,k,*a=list(map(int,open(0).read().split()))
    a,f=sorted(a[:n]),sorted(a[n:],reverse=1)
    ok=10**12
    ng=-1
    while ok-ng>1:
        mid=(ok+ng)//2
        l=k
        for b,g in zip(a,f):
            t=b-mid//g
            if t>0:l-=t
        if l<0:ng=mid
        else:ok=mid
    print(ok)
main()
# Original solution
n,k,*a=list(map(int,open(0).read().split()))
z=sorted(a[:n]),sorted(a[n:])[::-1]
o=10**12
g=-1
while o-g>1:
 m,l=o+g>>1,k
 for a,f in zip(*z):l-=max(0,a-m//f)
 if l<0:g=m
 else:o=m
print(o)

# Optimized solution
i,s=lambda:list(map(int,input().split())),sorted
n,k=i()
z=s(i()),s(i())[::-1]
o=10**12
g=-1
while o-g>1:
 m,l=o+g>>1,k
 for a,f in zip(*z):l-=max(0,a-m//f)
 if l<0:g=m
 else:o=m
print(o)
# 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)

ng = -1
ok = 10**18
while ok - ng > 1:
    mid = (ok + ng) // 2
    c = 0
    for i in range(N):
        c += max(0,A[i]-mid//F[i])
    if c <= K:
        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)
ng = -1
ok = 10**12+100
while ok - ng > 1:
    mid = (ok + ng) // 2
    c = 0
    for a,f in zip(A,F):
        c += max(0,a-mid//f)
    if c <= K:
        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(reverse=True)

ng = -1
ok = 10**12+100
while ok - ng > 1:
    mid = (ok + ng) // 2
    if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K:
        ok = mid
    else:
        ng = mid
print(ok)


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

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

ng = -1
ok = 10**12+100
while ok - ng > 1:
    mid = (ok + ng) // 2
    if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K:
        ok = mid
    else:
        ng = mid
print(ok)
# Original solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()
    f = list(map(int, readline().split()))
    f.sort(reverse=True)

    cor_v = 10 ** 22
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            if a[i] * f[i] >= bin_v:
                cost += ((a[i] * f[i]) - bin_v + f[i] - 1) // f[i]
            if cost > k:
                break
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()
    f = list(map(int, readline().split()))
    f.sort(reverse=True)

    cor_v = 10 ** 13
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            if a[i] * f[i] >= bin_v:
                cost += ((a[i] * f[i]) - bin_v + f[i] - 1) // f[i]
            if cost > k:
                break
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)


if __name__ == '__main__':
    solve()
# Original solution
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    f = list(map(int, input().rstrip('\n').split()))
    f.sort(reverse=True)
    cor_v = 10 ** 20
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            t = a[i] * f[i]
            if t > bin_v:
                cost += (t - bin_v + f[i] - 1) // f[i]
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    f = list(map(int, input().rstrip('\n').split()))
    f.sort(reverse=True)
    cor_v = 10 ** 13
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            t = a[i] * f[i]
            if t > bin_v:
                cost += (t - bin_v + f[i] - 1) // f[i]
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)


if __name__ == '__main__':
    solve()
# Original solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=sorted(a,reverse=True)
b=sorted(b)

def ok(N):
    sums=0
    for i in range(n):
        sums+=max(0,a[i]-N//b[i])
    if sums<=k:
        return True
    else:
        return False
    
import math

left=0
right=a[0]*b[-1]
P=0
for i in range(41):
    if 2**i<=right<2**(i+1):
        P=i+1
        break

for _ in range(P):
    if ok(math.floor((left+right)/2)):
      left=left
      right=(left+right)/2
    elif not ok(math.floor((left+right)/2)):
      left=(left+right)/2
      right=right
print((math.floor(right)))

# Optimized solution
# いきぬきreview　忘れた問題
# gluttony
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
F.sort()
A.sort(reverse=True)


def func(X):
    s = 0
    for i in range(N):
        a, f = A[i], F[i]
        s += max(0, a-X//f)
    return s <= K


R = 10**12
L = -1
while R-L > 1:
    m = (R+L)//2
    if func(m):
        R = m
    else:
        L = m
print(R)
# Original solution
from math import ceil
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)

left=0
right=10**12+1
ans=float("INF")
while True:
    mid=(left+right)//2

    now=0
    for i in range(N):
        if F[i]*A[i]>mid:
            now+=ceil(((F[i]*A[i])-mid)/F[i])
    #print(now, mid)
    if now==K:
        ans=min(ans, mid)
        right=mid
    elif now>K:
        if left==mid:
            break
        left=mid
    else:
        if right==mid:
            break
        right=mid
        ans=min(ans, mid)

print(ans)

# Optimized solution
from math import ceil
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)

left=0
right=10**12+1
ans=float("INF")
while True:
    mid=(left+right)//2

    now=0
    for i in range(N):
        if F[i]*A[i]>mid:
            now+=ceil(((F[i]*A[i])-mid)/F[i])
    #print(now, mid)
    if now==K:
        ans=min(ans, mid)
        if right==mid:
            break
        right=mid
    elif now>K:
        if left==mid:
            break
        left=mid
    else:
        if right==mid:
            break
        right=mid
        ans=min(ans, mid)

print(ans)
# 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)

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

def judge(n):
    score = 0
    for i in range(N):
        score += max(A[i] - n//F[i],0)
    return score<=K

def bisect(l,r):
    while r-l>1:
        if judge((l+r)//2):
            r = (l+r)//2
        else:
            l = (l+r)//2
    return r

if judge(0):
    print((0))
else:
    print((bisect(0,M)))


# 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)

def check(v):
    ans = 0
    for i in range(N):
        ans += max(A[i] - v//F[i],0)
    return ans<=K

if check(0):
    print((0))
else:
    l = 0
    r = 10**12 + 1
    while r-l>1:
        if check((l+r)//2):
            r = (l+r)//2
        else:
            l = (l+r)//2
    print(r)
# 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)
r = A[-1]*F[0]
l = -1
while(r-l > 1):
    tmp = (l+r)//2
    k = 0
    for x, y in zip(A, F):
        if x*y > tmp:
            k += x - (tmp // y)
        #k += max(0, x - (tmp // y))
    if K >= k:
        r = tmp
    else:
        l = tmp
print(r)


# Optimized solution
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)
    r = A[-1]*F[0]
    l = -1
    while(r-l > 1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            if x*y > tmp:
                k += x - (tmp // y)
            #k += max(0, x - (tmp // y))
        if K >= k:
            r = tmp
        else:
            l = tmp
    print(r)


main()
# 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)[::-1]


def c(x):
    # x決めると必要な修行回数も決まる
    res = 0
    for O, K in zip(a, f):
        d = max(0, O * K - x)
        res += (d + K - 1) // K
    return res <= k


l = -1
r = 1 << 60
while r - l > 1:
    mid = (l + r) >> 1
    if c(mid):
        r = mid
    else:
        l = mid
print(r)


# Optimized solution
n, k = list(map(int, input().split()))
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))[::-1]

# 成績　Σ{i=1~n}a[i]*f[i]
# a[i]小さいの、f[i]でかいの組み合わせるとよい(交換しても悪化しない)
def c(x):
    need = 0
    for i in range(n):
        if a[i] * f[i] > x:
            # f[i]を何回減らしてx以下にできるか
            diff = a[i] * f[i] - x
            need += 0 - - diff // f[i]
    return need <= k


l = 0
r = 1 << 60

while r != l:
    mid = (l + r) >> 1
    if c(mid):
        r = mid
    else:
        l = mid + 1
print(l)
# 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)

l = -1 # 絶対にfalse
r = 10**12+5
while (l+1<r):
  c = (l+r)//2
  s = 0
  for i in range(N):
    s += max(0, A[i]-(c//F[i]))
  if s <= K:
    r = c
  else:
    l = c

print(r)

# 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)

l = -1
r = 10**12+5

while (l+1<r):
  c = (l+r)//2
  tmp = 0
  for i in range(N):
    tmp += max(0, A[i]-(c//F[i]))
  
  if tmp <= K:
    r = c
  else:
    l = c

print(r)
# 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 isOk(x):
    cost = 0
    for a, f in zip(A,F):
        eatable = x//f
        if eatable >= a:
            continue
        cost += a - eatable
    if cost <= k:
        return True
    return False

left = -1
right = A[-1] * F[0]
while left+1 < right:
    mid = int(left + (right-left)//2)
    if isOk(mid):
        right = mid
    else:
        left = mid
print(right)

# 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)

def isOk(x):
    cost = 0
    for a, f in zip(A,F):
        eatable = x//f
        if eatable >= a:
            continue
        cost += a - eatable
    if cost <= k:
        return True
    return False

left = -1
right = A[-1] * F[0]
while left+1 < right:
    # mid = int(left + (right-left)//2)
    mid = (left+right)//2
    if isOk(mid):
        right = mid
    else:
        left = mid
print(right)