Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i.
In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows:
 - A team should assign one member to each food, and should not assign the same member to multiple foods.
 - It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish.
 - The score of a team is the longest time it takes for an individual member to finish the food.
Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total.
What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 2 \times 10^5
 - 0 \leq K \leq 10^{18}
 - 1 \leq A_i \leq 10^6\ (1 \leq i \leq N)
 - 1 \leq F_i \leq 10^6\ (1 \leq i \leq N)

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N
F_1 F_2 ... F_N

-----Output-----
Print the minimum possible score of the team.

-----Sample Input-----
3 5
4 2 1
2 3 1

-----Sample Output-----
2

They can achieve the score of 2, as follows:
 - Member 1 does 4 sets of training and eats Food 2 in (4-4) \times 3 = 0 seconds.
 - Member 2 does 1 set of training and eats Food 3 in (2-1) \times 1 = 1 second.
 - Member 3 does 0 sets of training and eats Food 1 in (1-0) \times 2 = 2 seconds.
They cannot achieve a score of less than 2, so the answer is 2.

Difficulty: interview

Starter code:

Solutions:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索
N, K = lr()
A = np.array(lr())
F = np.array(lr())
A.sort()
F = np.sort(F)[::-1]

def check(x):
    count = np.maximum(0, (A - (x // F))).sum()
    return count <= K

left = 10 ** 12 # 可能
right = -1 # 不可能
while left > right + 1:
    mid = (left+right) // 2
    if check(mid):
        left = mid
    else:
        right = mid

print(left)
# 51


import numpy as np

n,k=map(int,input().split())
a=[int(x) for x in input().split()]
f=[int(x) for x in input().split()]

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

A=np.array(a)
F=np.array(f)
S=sum(a)

l,u=-1,f[0]*a[-1]
while l+1<u:
  m=(l+u)//2
  s=0
  if S-np.minimum(A,m//F).sum()<=k:
    u=m
  else:
    l=m

print(u)

import numpy as np

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)

maxT = np.max(A*F)
# use binary search to find lowest possible T
left = -1
right = maxT
while left+1< right:
    mid = (left+right)//2
    if np.maximum(0, A - (mid//F)).sum() <= K:
        right  = mid
    else:
        left = mid
print(right)



import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索、浮き沈みの沈みに注意
N, K = lr()
A = np.array(lr()); A.sort()
F = np.array(lr()); F.sort(); F = F[::-1]

def check(x):
    cost = np.maximum(0, A - (x // F)).sum()
    return cost <= K

ok = 10 ** 15; ng = -1
while abs(ng-ok) > 1:
    mid = (ok+ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid

print(ok)


import numpy as np

def is_ok(mid, k):
    s = np.maximum(a - mid // f, 0).sum()
    if s <= k:
        return True
    else:
        return False

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
a = np.array(a)
f = np.array(f)

l, r = -1, np.max(a * f) # l:ng, r:ok
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, k):
        r = mid
    else:
        l = mid
print(r)

#!/usr/bin/env python3
import numpy as np


def is_ok(mid, K, A, F):
    return np.maximum(A - mid // F, 0).sum() <= K


def main():
    N, K = input_line(int, int)
    A = input_line([int])
    F = input_line([int])
    A = np.array(sorted(A))
    F = np.array(sorted(F, reverse=True))

    ng = -1
    ok = int(1e12)
    while ok - ng > 1:
        mid = (ng + ok) // 2
        if is_ok(mid, K, A, F):
            ok = mid
        else:
            ng = mid
    print(ok)


def input_line(*types):
    if isinstance(types[0], list):
        return [types[0][0](x) for x in input().split()]
    elif len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


def __starting_point():
    main()

__starting_point()

#import sys
import numpy as np
#input = sys.stdin.readline

def main():
    n, k=map(int, input().split())
    a=np.array(list(map(int, input().split())), dtype=np.int64)
    f=np.array(list(map(int, input().split())), dtype=np.int64)
    a=np.sort(a)
    f=np.sort(f)[::-1]
    l,r=0,10**12
    while l<=r:
        m=(l+r)//2
        tr=np.clip(a-m//f,0,None).sum()
        if tr>k:
            l=m+1
        else:
            r=m-1
    print(l)

def __starting_point():
    main()
__starting_point()

import sys
import numpy as np
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,k=map(int,input().split())
a=np.array(readline().split(),np.int64)
f=np.array(readline().split(),np.int64)
a.sort()
f.sort()
f=f[::-1]
def test(x):
  return np.maximum(0,a-x//f).sum()<=k

l=-1
r=INF
while l+1<r:
  mid=(l+r)//2
  if test(mid):
    r=mid
  else:
    l=mid
    
print(r)

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

import numpy as np
a = np.array(a)
f = np.array(f)

low = -1
hi = 10**18

while hi-low > 1:
    ave = (hi+low)//2
    if np.maximum(0,a-ave//f).sum() <= k:
        hi = ave
    else:
        low = ave

print(hi)

import numpy as np
def solve(n, k, a, f):
    a = sorted(a)
    f = sorted(f)[::-1]
    a = np.asarray(a, dtype=int)
    f = np.asarray(f, dtype=int)
    total = np.sum(a)
    l = -1
    r = np.max(a*f)
    while r - l > 1:
        th = (l + r) // 2
        cost = total - np.minimum(a, th // f).sum()
        if cost <= k:
            r = th
        else:
            l = th
    return r

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
print(solve(n, k, a, f))

import numpy as np


def main():
    N, K = [int(x) for x in input().split()]
    A = [float(x) for x in input().split()]
    F = [float(x) for x in input().split()]

    A = np.array(sorted(A))
    F = np.array(sorted(F, reverse=True))

    if K >= np.sum(A)*N:
        print((0))
        return

    min_time = 0
    max_time = A[-1] * F[0]

    while max_time != min_time:
        tgt_time = (min_time + max_time)//2
        ideal_a = np.floor(tgt_time*np.ones(N)/F)
        cost = A - ideal_a
        require_k = np.sum(cost[cost > 0])
        if require_k <= K:
            max_time = tgt_time
        else:
            min_time = tgt_time+1

    print((int(max_time)))


def __starting_point():
    main()

__starting_point()

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()

import numpy as np

a = np.array(a)
f = np.array(f)
f_ = f[::-1]

left = -1
right = np.max(a*f_)

while left + 1 < right:
    mid = (left + right)//2
    x = np.maximum(0, a - (mid//f_) ).sum() <= k
    if x:
        right = mid
    else:
        left = mid

print(right)

N,K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A)
F=sorted(F)[::-1]
import numpy as np
a=np.array(A)
f=np.array(F)

low=-1
high=10**18

while high-low>1:
  d=(high+low)//2
  #0かa-d//fの大きい値を採用するnp.maximum　
  if np.maximum(0,a-d//f).sum()<=K:
    high=d
  else:
    low=d
print(high)

import sys
input = sys.stdin.readline

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

#output
import numpy as np
A = np.array(A)
F = np.array(F)

A = np.sort(A)[::-1]
F = np.sort(F)
B = np.sum(A)
M = max([a*f for a, f in zip(A, F)])

def is_possible(x):
    return B - np.minimum(A, x//F).sum() <= K

left = -1
right = M
while left + 1 < right:
    mid = (left + right)//2
    if is_possible(mid):
        right = mid
    else:
        left = mid

print(right)

def abc144_e():
    import numpy as np

    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
    F = np.array(input().split(), dtype=np.int64)
    A = np.sort(A)
    F = np.sort(F)[::-1]

    low = -1
    up = 10**12
    while up - low > 1:
        v = (up + low) // 2
        x = A - v // F
        if x[x > 0].sum() > K:
            low = v
        else:
            up = v
    print(up)

def __starting_point():
    abc144_e()
__starting_point()

from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    A=np.array(list(map(int,readline().split())),dtype=np.int64)
    A=np.sort(A)[::-1]
    F=np.array(list(map(int,readline().split())),dtype=np.int64)
    F=np.sort(F)

    l=-1
    r=10**12
    while l<r-1:
        x=(l+r)//2
        A_after=np.minimum(x//F,A)
        cnt=(A-A_after).sum()
        if cnt<=k: r=x
        else: l=x

    print(r)

def __starting_point():
    main()
__starting_point()

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索、浮き沈みの沈みに注意
N, K = lr()
A = np.array(lr()); A.sort()
F = np.array(lr()); F.sort(); F = F[::-1]

def check(x):
    limit = x // F # このラインまでにAを落とす
    Y = A - limit
    cost = Y[Y>=0].sum()
    return cost <= K

ok = 10 ** 15; ng = -1
while abs(ng-ok) > 1:
    mid = (ok+ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid

print(ok)


import sys
input = sys.stdin.readline
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()


import numpy as np
from numba import njit

n, k = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

A = np.sort(A)
F = np.sort(F)[::-1]

@njit
def is_ok(x):
    tmp = 0
    for a, f in zip(A, F):
        y = a * f
        if y > x:
            tmp += a - x // f
    return tmp <= k

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

print(ok)


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def bs(f, mi, ma):
    mm = -1
    while ma > mi:
        mm = (ma+mi) // 2
        if f(mm):
            mi = mm + 1
        else:
            ma = mm
    if f(mm):
        return mm + 1
    return mm

def main():
    n,k = LI()
    a = sorted(LI())
    b = sorted(LI(), reverse=True)
    if sum(a) <= k:
        return 0

    def f(i):
        t = 0
        for ai,bi in zip(a,b):
            u = i // bi
            if ai > u:
                t += ai - u
        return t > k

    r = bs(f,0,10**12)

    return r


print(main())





def main():
    import numpy as np
    import sys
    input = sys.stdin.readline
    N, K = list(map(int,input().split()))
    A = np.sort(list(map(int,input().split())))
    F = np.sort(list(map(int,input().split())))[::-1]

    if K >= np.sum(A)*N:
        print((0))
        return
    ma = A[-1]*F[0]
    mi = 0
    A = A*F
    while ma != mi:
        tgt = (ma + mi)//2
        tmp = np.ceil((A-tgt)/F)
        if np.sum(tmp[tmp>0]) <= K:
            ma = (ma + mi)//2
        else:
            mi = (ma + mi)//2+1
    print(ma)
def __starting_point():
    main()

__starting_point()

N,K = map(int,input().split())

import numpy as np

A = np.array(input().split(),np.int64)
B = np.array(input().split(),np.int64)

A.sort() ; B.sort() 
B=B[::-1]

right = max(A*B)   #時間の可能集合の端点
left = -1           #時間の不可能集合の端点

def test(t):
    
    C = A-t//B
    D= np.where(C<0,0,C)
    return D.sum()<=K

while left+1<right:
    mid = (left+right)//2
    if test(mid):
        right=mid
    else:
        left = mid

print(right)

import numpy as np
import sys
input = sys.stdin.readline
N, K = list(map(int,input().split()))
A = np.sort(list(map(int,input().split())))
F = np.sort(list(map(int,input().split())))[::-1]
mul = A*F
if K >= np.sum(A)*N:
    print((0))
    return

ma = A[-1]*F[0]
mi = 0
while ma != mi:
    tgt = (ma + mi)//2
    tmp = np.ceil((mul-tgt)/F)
    num = np.sum(tmp[tmp>0])
    if num <= K:
        ma = (ma + mi)//2
    else:
        mi = (ma + mi)//2+1
print(ma)


import numpy as np
N, K = map(int,input().split())
A = np.array(list(map(int,input().split())))
F = np.array(list(map(int,input().split())))
A.sort()
F.sort()
A = A[::-1]
left = 0
right = np.max(A * F)
for _ in range(50):
    judge = (left + right) // 2
    rec = judge // F
    recK = np.sum(np.maximum(np.zeros(N), A - rec))
    if recK <= K:
        right = judge
    else:
        left = judge + 1
    if left == right:
        print(left)
        break

import sys
readline = sys.stdin.readline

import numpy as np

N,K = list(map(int,readline().split()))
A = np.sort(np.array(readline().split(), dtype = int))
F = np.sort(np.array(readline().split(), dtype = int))[::-1]

# X秒で完食できるか二分探索

ng = -1
ok = F[0] * A[-1]

def isOk(x):
  return A.sum() - np.minimum(A, x // F).sum() <= K
  
while abs(ok - ng) > 1:
  mid = abs(ok + ng) // 2
  if isOk(mid):
    ok = mid
  else:
    ng = mid
    
print(ok)



import numpy as np

def is_ok(mid, k):
    s = np.maximum(a - mid // f, 0).sum()
    if s <= k:
        return True
    else:
        return False

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
f = np.array(list(map(int, input().split())))
a = np.sort(a)
f = np.sort(f)[::-1]

l, r = -1, np.max(a * f) # l:ng, r:ok
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, k):
        r = mid
    else:
        l = mid
print(r)

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(reverse=True)

def score(x):
    syugyo = 0
    for A,F in zip(a,f):
        sup = x//F
        if sup < A:
            syugyo += A-sup
    if syugyo <= k:
        return True
    return False


left = 0
right = a[-1]*f[0]+1
while left < right-1:
    mid = (left+right)//2
    if score(mid):
        right = mid
    else:
        left = mid
print((left+1 if left != 0 else 0))


import numpy as np

def is_ok(mid, k):
    s = a - mid // f
    s = s[s > 0].sum()
    if s <= k:
        return True
    else:
        return False

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
a = np.array(a)
f = np.array(f)

l, r = -1, 10**12 # l:ng, r:ok
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, k):
        r = mid
    else:
        l = mid
print(r)

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 is_lessthanK(X):
  ans=0
  for A,F in zip(a,f):
    if A*F>X:
      ans+=A-X//F
    if ans > k:
      return False
  return True


ng=-1
ok=a[-1]*f[0]
while ok-ng>1:
  mid=(ok+ng)//2
  if is_lessthanK(mid):
    ok=mid
  else:
    ng=mid
print(ok)



import numpy as np

def main():
    N, K = list(map(int, input().split()))
    A = np.array(list(map(int, input().split())))
    F = np.array(list(map(int, input().split())))

    A.sort()
    F = np.sort(F)[::-1]

    time = A*F
    high = 10**12 + 1
    low = -1

    while high - low > 1:
        middle = (high + low) // 2

        temp = np.where(time>middle, time-middle, 0)
        temp = np.ceil(temp/F).sum()

        if temp <= K:
            high = middle
        else:
            low = middle

    print(high)


def __starting_point():
    main()

__starting_point()

# # もし修行により消化コストが全て0になる場合
# if sum(a_list) <= k:
#     print(0)
#     return

# # 更新メソッド
# def update_cost(max_idx, result_cost, a_list, f_list):

#     result_cost[max_idx] = a_list[max_idx] * f_list[max_idx]

#     if max_idx == 0:
#         pass
#     else:
#         result_cost[max_idx-1] = a_list[max_idx-1] * f_list[max_idx-1]

#     return result_cost

# # ソート
# a_list.sort()
# f_list.sort(reverse=True)

# # コストリストinit
# result_cost = [a_list[idx] * f_list[idx] for idx in range(len(a_list))]


# # 修行する
# while k > 0:
#     # 現状で最もコストが大きいものについて考える
#     max_idx = result_cost.index(max(result_cost))

#     # 修行実行
#     a_list[max_idx] -= 1
#     a_list.sort()

#     # コストリスト更新
#     result_cost = update_cost(max_idx, result_cost, a_list, f_list)

#     # 修行数減らす
#     k -= 1

# print(max(result_cost))

import numpy as np
n, k = list(map(int, input().split()))

A = np.array(input().split(), np.int)
F = np.array(input().split(), np.int)

A.sort()
F.sort()
F = F[::-1]

left = -1 
right = (A * F).sum()

while (right-left) > 1:
    # print(left, right)
    split_line = (left + right) // 2
    r = np.maximum(0, A-split_line // F).sum() <= k
    if r:
        right = split_line
    else:
        left = split_line

print(right)



def main():
    import numpy as np
    import sys
    input = sys.stdin.readline
    N, K = map(int,input().split())
    A = np.sort(list(map(int,input().split())))
    F = np.sort(list(map(int,input().split())))[::-1]
    mul = A*F
    if K >= np.sum(A)*N:
        print(0)
        return

    ma = A[-1]*F[0]
    mi = 0
    while ma != mi:
        tgt = (ma + mi)//2
        num = np.sum(np.maximum(0,(mul-tgt+F-1)//F))
        if num <= K:
            ma = (ma + mi)//2
        else:
            mi = (ma + mi)//2+1
    print(ma)
def __starting_point():
    main()
__starting_point()

import sys
import numpy as np


n, k = map(int,input().split())

a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))

asum = a.sum()

l,r = 0, 10**13
while l != r:
    mid = (l+r)//2

    can = (asum - np.minimum(mid//f, a).sum()) <= k

    if can:
        r = mid 
    else:
        l = mid +1

print(l)

import numpy as np

n,k=map(int,input().split())

a=np.array(input().split(),dtype=np.int64)
f=np.array(input().split(),dtype=np.int64)

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

# r以下にするのに必要修行回数がk以内かどうか
def safe(r):
    return (np.maximum(0,(af-r+f-1)//f)).sum()<=k
    
m=-1
M=10**12

while m+1<M:
    pos=(m+M)//2
    if safe(pos):
        M=pos
    else:
        m=pos
print(M)

import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = np.array(LI())
    F = np.array(LI())

    A.sort()
    F.sort()
    F = F[::-1]

    # 時間tで感触できるか
    def can_complete(t):
        return np.maximum(0, A-t//F).sum() <= K

    # for j in range(20):
    #     print(can_complete(j))

    ng = -1
    ok = max(A)*max(F)
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_complete(m):
            ok = m
        else:
            ng = m
    print(ok)

def __starting_point():
    resolve()

__starting_point()

import numpy as np
N, K = map(int, input().split())
A = [int(c) for c in input().split()]
F = [int(c) for c in input().split()]
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)
Asum = A.sum()
M = np.max(A*F)

l = -1
r = M+1
while l+1<r:
  s = (l+r)//2
  cnt = Asum - np.minimum(A, s//F).sum()
  if cnt>K:
    l = s
  else:
    r = s

print(r)

import numpy as np

n,k=list(map(int,input().split()))
a=np.array(input().split(),dtype=int)
f=np.array(input().split(),dtype=int)

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

ok=10**18
ng=-1

import math
def isOK(val,arr,farr,k):
  return arr.sum()-np.minimum(arr,val//farr).sum()<=k
  
while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOK(mid,a,f,k):
    ok=mid
  else:
    ng=mid
    
print(ok)


import numpy as np
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
A = np.sort(list(map(int,input().split())))
F = np.sort(list(map(int,input().split())))[::-1]
mul = A*F
if K >= sum(A)*N:
    print(0)
    return

ma = 2**40
mi = 0
while ma != mi:
    tgt = (ma + mi)//2
    tmp = np.ceil((mul-tgt)/F)
    num = np.sum(tmp[tmp>0])
    if num <= K:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2+1
print(ma)


import numpy as np
def resolve():
    # 達成スコアを決める
    # 修行回数がK以下を達成できるスコアを二分探索
    def check(X):
        # 修行をしてスコアを最小化する
        a = X // F
        diff = np.maximum(A - a, 0)
        cnt = np.sum(diff)
        return cnt <= K

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

    A.sort()
    F.sort()
    F = F[::-1]

    ok = 10 ** 12  # 最大スコア a: 10**6 * x:10**6
    ng = -1
    while ok - ng > 1:
        X = (ok + ng) // 2
        if check(X):
            ok = X
        else:
            ng = X

    print(ok)


def __starting_point():
    resolve()

__starting_point()

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


import numpy as np


def solve():
    N, K = map(int, input().split())
    a_l = np.array(input().split(), int)
    b_l = np.array(input().split(), int)
    a_l.sort()
    b_l.sort()
    b_l = b_l[::-1]

    sum_a = a_l.sum()
    left, right = -1, 10**13
    while left + 1 < right:
        mid = (left + right) // 2
        if sum_a - np.minimum(a_l, mid // b_l).sum() <= K:
            right = mid
        else:
            left = mid

    print(right)


def __starting_point():
    solve()
__starting_point()

def main():
    import sys
    input=sys.stdin.readline
    import numpy as np

    n,k=list(map(int,input().split()))
    A=np.array(input().split(),dtype=np.int64)
    F=np.array(input().split(),dtype=np.int64)
    A.sort()
    F.sort()
    F=F[::-1]

    def ok(x): #チームの成績をxとするような修行の仕方が存在するか
        cnt=np.maximum(0,A-x//F).sum()
        return cnt<=k
    
    l=-1
    r=10**12+1
    while r-l>1:
        mid=(r+l)//2
        if ok(mid):
            r=mid
        else:
            l=mid
    print(r)   

def __starting_point():
    main()


__starting_point()

import numpy as np
N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A = np.sort(A)
F = np.sort(F)[::-1]


def C(x):
    train = np.maximum(0, A - x // F).sum()
    return train <= K


left = -1
right = 10 ** 12 + 1
while right > left + 1:
    mid = (right + left) // 2
    if C(mid):  # 食べきれる場合
        right = mid
    else:
        left = mid

ans = right
print(ans)



import numpy as np
 
a,b=map(int,input().split())
A=np.array(sorted(list(map(int,input().split()))))
F=np.array(sorted(list(map(int,input().split())),reverse=True))
 
s=A.sum()
 
x=-1
y=10**12
while x+1<y:
  mid=(x+y)//2
  if s-np.minimum(A,mid//F).sum()<=b:
    y=mid
  else:
    x=mid
print(y)

import numpy as np

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

A = np.array(A, np.int64)
F = np.array(F, np.int64)

Asum = sum(A)

def test(X):
    return (Asum - np.minimum(A, X//F).sum() <= K)

l = -1
r = 10**12

while (l + 1 < r):
    mid = (l + r) // 2
    if test(mid):
        r = mid
    else:
        l = mid

ans = r
print(ans)


import sys
import numpy as np


n, k = map(int,input().split())

a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))

asum = a.sum()

l,r = 0, 10**13
while l != r:
    mid = (l+r)//2

    can = (asum - np.minimum(mid//f, a).sum()) <= k

    if can:
        r = mid
    else:
        l = mid +1

print(l)

import numpy as np


def is_good(mid, key):
    x = A - mid // F
    return x[x > 0].sum() <= key


def binary_search(key):
    bad, good = -1, 10 ** 18
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A.sort()
F[::-1].sort()
print((binary_search(K)))


import sys
readline = sys.stdin.readline

import numpy as np

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

ok = A[-1] * F[0]
ng = -1

def isOk(x):
  # 時間がxになるためには、A_iをx/F_i以下まで減らす必要がある
  return A.sum() - np.minimum(A,x // F).sum() <= K
  
while (ok - ng)>1:
  mid = (ok + ng) // 2
  if isOk(mid):
    ok = mid
  else:
    ng = mid
print(ok)

import numpy as np

n,k = map(int,input().split())
a = np.array(list(map(int,input().split())))
f = np.array(list(map(int,input().split())))

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

def test(x):
    return np.maximum(0,a-x//f).sum() <= k

def nibutan(low,hi):
    while True:
        ave = (low+hi)//2
        #ここの条件式を問題文に合わせる
        if test(ave):
            hi = ave
        else:
            low = ave
        if hi - low == 1:
            break
    li = [low,hi]
    return li

li = nibutan(-1,10**12)

print(li[1])

# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n, k = list(map(int, args[0].split()))
    A = np.array(sorted(list(map(int, args[1].split()))))
    F = np.array(sorted(list(map(int, args[2].split())), reverse=True))

    right = 1+A[-1]*F[0]
    left = -1

    total = A.sum()
    while left+1 < right:
        mid = (left+right)//2
        if total - np.minimum(A, mid//F).sum() <= k:
            right = mid
        else:
            left = mid

    return str(right)


def __starting_point():
    print((solve(*(open(0).read().split('\n')))))

__starting_point()

import numpy as np
def bin_search(left, right, check):
    while left + 1 < right:
        middle = (left + right) >> 1
        if check(middle):
            right = middle
        else:
            left = middle
    return right

def make_check(A, F, Z, K):
    def check(m):
        return np.maximum(A - m // F, Z).sum() <= K
    return check

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)
F = np.array(input().split(), dtype=np.int32)
Z = np.zeros((N,), dtype=np.int32)
A.sort()
F = F[np.argsort(-F)]
check = make_check(A, F, Z, K)

print(bin_search(-1, 10 ** 12, check))

import numpy as np


def is_good(mid, key):
    return A_sum - np.minimum(A, mid // F).sum() <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A.sort()
F[::-1].sort()
A_sum = A.sum()
ans = binary_search(-1, np.max(A * F), K)
print(ans)


import numpy as np
N, K = map(int, input().split())
A = np.array(tuple(map(int, input().split())))
F = np.array(tuple(map(int, input().split())))

if sum(A) <= K:
    print(0)
else:
    def solve(N, K, A, F):
        A = np.sort(A)
        F = np.sort(F)[::-1]
        l = -1
        r = 10**12
        while (r - l) > 1:
            mid = (r + l) // 2
            # 成績がmidだったとして、修行しなければならない回数を算出
            fmid = (np.fmax([0]*N, A - (mid // F))).sum()
            if fmid <= K:
                r = mid
            else:
                l = mid
        return(r)
    print(solve(N, K, A, F))

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索、浮き沈みの沈みに注意
N, K = lr()
A = np.array(lr()); A.sort()
F = np.array(lr()); F.sort()
F = F[::-1]

def check(x):
    limit = x // F # このラインまでにAを落とす
    Y = A - limit
    if np.any(Y > K):
        return False
    cost = Y[Y>=0].sum()
    if cost <= K:
        return True
    else:
        return False

ok = 10 ** 15; ng = -1
while abs(ng-ok) > 1:
    mid = (ok+ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid

print(ok)


import sys
import numpy as np
N,K=map(int,input().split())
A=np.array([int(i) for i in input().split()])
F=np.array([int(i) for i in input().split()])
A=np.sort(A)
F=np.sort(F)[::-1]
 
Asum = A.sum()
def test(x):
    return Asum - np.minimum(A,x//F).sum() <= K
 
l=0
r=10**18*2+1
while r-l > 1:
    #print(l,r)
    m = (l+r)//2
    if test(m):
        r=m
    else:
        l=m
if test(l):
    print(l)
else:
    print(l+1)

def main():
    import numpy as np
    n, k = list(map(int, input().split()))
    aa = np.array(sorted(list(map(int, input().split()))), dtype=np.int64)
    f = np.array(sorted(list(map(int, input().split())),
                        reverse=True), dtype=np.int64)

    a = 0
    b = 10**12+10
    while a+1 < b:
        med = (a+b)//2
        if np.sum(np.maximum(aa-med//f, np.zeros(n, dtype=np.int64))) > k:
            a = med+1
        else:
            b = med
    if a == b:
        print(a)
    else:
        if np.sum(np.maximum(aa-a//f, np.zeros(n, dtype=np.int64))) > k:
            print(b)
        else:
            print(a)


main()


import numpy as np
N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A = np.sort(A)
F = np.sort(F)[::-1]


def C(x):
    train = np.maximum(0, A - x // F).sum()
    return train <= K


left = -1
right = 10 ** 12 + 1
while right > left + 1:
    mid = (right + left) // 2
    if C(mid):  # 食べきれる場合
        right = mid
    else:
        left = mid

ans = right
print(ans)


import numpy as np
N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A = np.sort(A)
F = np.sort(F)
F = F[::-1]


def C(m):
    need = m // F
    cost = A - need
    cost[cost < 0] = 0
    return cost.sum() <= K


l, r = -1, 10 ** 18 + 10
while r - l > 1:
    m = (r + l) // 2
    if C(m):
        r = m
    else:
        l = m

print(r)


import numpy as np

n,k=map(int,input().split())
a=[int(x) for x in input().split()]
f=[int(x) for x in input().split()]

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

a=np.array(a)
f=np.array(f)
s=a.sum()

l,u=-1,f[0]*a[-1]
while l+1<u:
  m=(l+u)//2
  if s-np.minimum(a,m//f).sum()<=k:
    u=m
  else:
    l=m

print(u)

import numpy as np
def bin_search(left, right, check):
    while left + 1 < right:
        middle = (left + right) >> 1
        if check(middle):
            right = middle
        else:
            left = middle
    return right

def check(m):
    return np.maximum(A - m // F, Z).sum() <= K

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)
F = np.array(input().split(), dtype=np.int32)
Z = np.zeros((N,), dtype=np.int32)
A.sort()
F = F[np.argsort(-F)]

print(bin_search(-1, 10 ** 12, check))

import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())), dtype = np.int64)
F = np.array(list(map(int, input().split())), dtype = np.int64)
A.sort()
F.sort()
F = F[::-1]

l = 0
r = 10**12 + 100

def solve(num):
	B = num // F
	tmp = np.sum(np.maximum(0, A - B))
	if tmp <= K:
		return 1
	else:
		return 0

while r - l > 1:
	mid = (l + r) // 2
	if solve(mid):
		r = mid
	else:
		l = mid

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



import numpy as np
N, K = map(int, input().split())
As = np.array(sorted(map(int, input().split())))
Fs = np.array(sorted(map(int, input().split()), reverse = True))

times = As * Fs

ng = -1
ok = np.amax(times)+1

while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    k = np.sum(np.maximum(np.ceil((times - mid) / Fs), 0))
    if k > K:
        ng = mid
    else:
        ok = mid

print(ok)

import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), np.int64)
F = np.array(input().split(), np.int64)
A.sort()
F.sort()
F = F[::-1]
dig = A.sum()


def judge(x):
    return dig - np.minimum(A, x // F).sum() <= K


l = -1
r = 10 ** 18 + 1

while l + 1 < r:
    test = (l + r) // 2
    if judge(test):
        r = test
    else:
        l = test

print(r)

import numpy as np

n, k = map(int,input().split()) 
a = list(map(int, input().split()))
f = list(map(int, input().split()))

if k > sum(a):
    print(0)
    return

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

a = np.array(a)
f = np.array(f)

lb = -1
ub = a[0]*f[-1]

while ub - lb > 1:
    x = (lb+ub)//2
    cx = np.full(n, x)
    ck = a - x//f
    ck = np.where(ck < 0, 0, ck)
    ck_sum = ck.sum()
    if ck_sum > k:
        lb = x
    else:
        ub = x
print(ub)

import sys
input = sys.stdin.readline

import numpy as np

def main():
  n, k = list(map(int, input().split()))
  A = np.array(sorted(list(map(int, input().split()))))
  F = np.array(sorted(list(map(int, input().split())), reverse=True))
  def is_time(x):
    c = np.maximum(A - x//F, 0).sum()
    if c <= k:
      return True
    return False
  ng = -1
  ok = max(A*F)
  while ok - ng > 1:
    m = (ng + ok)//2
    if is_time(m):
      ok = m
    else:
      ng = m
  print(ok)
  
def __starting_point():
  main()

__starting_point()

import numpy as np
n,k = list(map(int,input().split()))

A = np.array(input().split(),np.int)

F = np.array(input().split(),np.int)


A.sort()
F.sort()

F_ = F[::-1]

left = -1
right = (A * F_).sum()

while (right - left) > 1:
    s = (left + right) // 2
    r = np.maximum(0, A - s // F_).sum() <= k
    if r:
        right = s 
    else:
        left = s 

print(right)


import numpy as np
N, K = map(int, input().split())
As = np.sort(list(map(int, input().split())))
Fs = np.sort(list(map(int, input().split())))[::-1]
l  = As*Fs
left = 0
right = max(l)
while right-left>=1:
    mid = left + (right - left)/2
    if np.maximum(As-mid//Fs , 0).sum()<=K:
        right = mid
    else:
        left = mid
print(int(right))

import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    a = np.array(sorted(list(map(int, input().split()))))
    f = np.array(sorted(list(map(int, input().split())), reverse=True))

    Asum = a.sum()

    l, r = 0, int(1e13)
    while l != r:
        p = (l + r) // 2
        tmp = Asum - np.minimum(a, p//f).sum() <= K
        # print(p, tmp)
        if tmp:
            r = p
        else:
            l = p + 1
    
    print(l)


def __starting_point():
    main()
__starting_point()

import math
import numpy as np
def yn(a, f, k, x):
  k_yt = np.maximum(np.zeros(a.shape),a - np.floor(np.divide(x, f)))
  k_yt = np.sum(k_yt)
  if k_yt <= k:
    return True
  else:
    return False

n, k = list(map(int, input().split()))
a = list((list(map(int, input().split()))))
f = list((list(map(int, input().split()))))
a.sort()
f.sort(reverse = True)
xo = max([a[i]*f[i] for i in range(n)])
a = np.array(a)
f = np.array(f)
# binary search
if xo == 0:
  print((0))
else:
  l = 0
  r = xo
  m = xo
  while l <= r:
    piv = int((r+l)/2)
    if yn(a, f, k, piv):
      r = piv - 1 
      m = piv
    else:
      l = piv +1
  print(m)
   
    



import numpy as np

def solve(n, k, aaa, fff):
    aaa = np.sort(aaa)
    fff = np.sort(fff)[::-1]

    l = -1
    r = 1e12
    while l+1 < r:
        c = (l+r)//2
        s = np.clip(aaa - c//fff, 0, None).sum()
        if s <= k:
            r = c
        else:
            l = c
    return int(r)


n, k = map(int, input().split())
aaa = np.array(list(map(int, input().split())), dtype=np.int64)
fff = np.array(list(map(int, input().split())), dtype=np.int64)

print(solve(n, k, aaa, fff))

import numpy as np

def main():
    N, K = list(map(int, input().split()))
    A = np.array(list(map(int, input().split())))
    F = np.array(list(map(int, input().split())))

    A.sort()
    F = np.sort(F)[::-1]

    time = A*F
    high = 10**12 + 1
    low = -1

    while high - low > 1:
        middle = (high + low) // 2

        temp = np.where(time>middle, time-middle, 0)
        temp = np.ceil(temp/F).sum()

        if temp <= K:
            high = middle
        else:
            low = middle

    middle = high
    temp = np.where(time>middle, time-middle, 0)
    temp = np.ceil(temp/F)
    time = (time - temp*F).max()
    print((int(time)))


def __starting_point():
    main()

__starting_point()