Problem:
 Score: 500 points    Problem Statement  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 1 3 5
4 2 1
2 3 1      Sample Output 1 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 .       Sample Input 2 3 8
4 2 1
2 3 1      Sample Output 2 0  They can choose not to do exactly K sets of training.       Sample Input 3 11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2      Sample Output 3 12

Solution (Python):
n,k=map(int,input().split())
A=sorted(list(map(int,input().split())))
F=sorted(list(map(int,input().split())),reverse=True)
ng=-1
ok=10**12+10
while ok-ng>1:
  mid=(ok+ng)//2
  a=0
  for i in range(n):
    a=a+max(0,A[i]-mid//F[i])
  if a>k:
    ng=mid
  else:
    ok=mid
print(ok)

Solution (Python):
def is_ok(a_list, f_list, score, k):
    cnt = 0
    for i in range(len(a_list)):
        target = score // f_list[i]
        cnt += max(0, a_list[i] - target)
        if cnt > k:
            return False
    return True


n, k = map(int, input().split())
a_list = list(map(int, input().split()))
f_list = list(map(int, input().split()))

a_list.sort()
f_list.sort()
f_list.reverse()

ok, ng = 10 ** 12, -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(a_list, f_list, mid, k):
        ok = mid
    else:
        ng = mid
print(ok)

Solution (Python):

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = -1, 10**12 + 1  

while r - l > 1:
    mid = (r + l) // 2  
    cur = 0
    for i in range(n):
        if a[i] * b[i] <= mid:
            
            pass
        else:
            
            cur += a[i] - mid // b[i]
    if cur > k:
        l = mid
    else:
        r = mid
print(r)

Solution (Python):

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = -1, 10**12 + 1  

while r - l > 1:
    mid = (r + l) // 2  
    cur = 0
    for i in range(n):
        if a[i] * b[i] <= mid:
            
            pass
        else:
            
            cur += a[i] - mid // b[i]
        if cur > k:
            l = mid
            break
        
        
        
    if cur > k:
        l = mid
    else:
        r = mid
print(r)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if sum(A) <= K:
    print(0)
    exit()

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

A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12
while l + 1 < r:
    c = (l + r) // 2
    if ok(c):
        r = c
    else:
        l = c
print(r)

Solution (Python):
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
U = 10**12
L = -1
while U - L > 1:
    x = (U+L)//2
    cnt = 0
    for i in range(N):
        if x//F[i] < A[i]:
            cnt += A[i] - x//F[i]
    if cnt > K:
        L = x
    else:
        U = x
print(U)

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

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

hi = 10**18
lo = -1

while hi - lo > 1:
    mid = (hi + lo) // 2
    tr = 0
    for i in range(N):
        if A[i] * F[i] > mid:
            tr += A[i] - mid // F[i]
    if tr > K:
        lo = mid
    else:
        hi = mid

print(hi)

Solution (Python):
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))

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    N,K = 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,max(a)*max(f)+1
    
    while r-l>1:
        mid = (r+l)//2
        count = 0
        for cost,dif in zip(a,f):
            if mid >= cost*dif:
                continue
            rest = cost*dif-mid
            count += -(-rest//dif)
        if count <= K:
            r = mid
        else:
            l = mid
            
    print(r)

if __name__ == "__main__":
    main()

Solution (Python):
mod = 10 ** 9 + 7
from collections import deque
import heapq


def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def main():
    r = solve()
    print(r)


def solve():
    N, K = iip(False)
    A = iip(True)
    F = iip(True)

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

    l = -1
    r = 10**12
    while r - l > 1:

        x = (l+r)//2
        nk = 0

        for a, f in zip(A, F):
            lima = x // f
            
            syugyou = a - lima
            
            if x <= 10:
                
                pass
            nk += max(0, syugyou)


        if nk > K:
            l = x
        else:
            r = x

    

    return r




def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p - 1)) % mod


if __name__ == "__main__":
    main()

Solution (Python):

import numpy as np


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)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

n, k = map(int, readline().split())
a = np.array(readline().split(), np.int64)
f = np.array(readline().split(), np.int64)
a.sort()
f.sort()
f = f[::-1]
a_sum = a.sum()
left = - 1
right = 10 ** 12

while left + 1 < right:
    mid = (left + right) // 2
    if a_sum - np.minimum(a, mid // f).sum() <= k:
        right = mid
    else:
        left = mid

print(right)

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

lim = sum(a) -k
if(lim <= 0):
    print(0)
    exit()

min_ = 0
max_ = 10**12+1

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

for i in range(100):
    tmp = (max_ + min_)//2
    tmp_sum = 0
    for j in range(n):
        tmp_sum += max(0, a[j] - tmp//f[j])

    if(tmp_sum <= k):
        max_ = tmp
    else:
        min_ = tmp

    if(max_ - min_ == 1):
        break

print(max_)

Solution (Python):
import sys

def input():
    return sys.stdin.readline().rstrip('\n')



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)
AxF = [A[i]*F[i] for i in range(N)]
AxFmax = max(AxF)

def is_possible(x):
    _sum = 0
    for i in range(N):
        _sum += max(0, A[i] - x//F[i])
    
    return _sum <= K

left = 0
right = AxFmax

while(left != right):
    x = (left+right)//2
    if is_possible(x):
        right = x
    else:
        left = x+1
    
            
print(left)

Solution (Python):
def main():
    import math
    import sys
    input = sys.stdin.readline

    n,k = map(int,input().split())
    a = sorted(list(map(int,input().split())))
    f = sorted(list(map(int,input().split())),reverse=True)
    check = []
    for i in range(n):
        check.append((a[i]*f[i],a[i],f[i]))

    def search(x):
        count = 0

        for i,j,k in check:
            if i > x:
                y = math.floor(x/k)
                count += j-y
        return count

    left = -1
    right = 10**12+2
    while right > left+1:
        mid = (right+left)//2
        if search(mid) > k:
            left = mid
        else:
            right = mid
    print(right)
if __name__ == "__main__":
    main()

Solution (Python):
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)

Solution (Python):
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 
    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)

Solution (Python):
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 
    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)

Solution (Python):
import sys
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
h,l=max(a[i]*f[i] for i in range(n))+1,0

if sum(a)<=k: print(0);sys.exit()

while h-l>1:
    m=(h+l)//2
    practice=sum(max(0,a[i]-m//f[i]) for i in range(n))
    if practice<=k: h=m
    else: l=m
print(h)

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

def solve(x):
    lk = k
    for i, j in zip(a, f):
        if i*j<=x:
            continue
        lk -= (j*(i+1)-x-1)//j
        if lk<0:
            return False
    return True

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

print(ok)

Solution (Python):
n,k = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
l,r = 0, 10**18
if sum(A)<=k:
    print(0)
else:
    while r-l!=1:
        mid = (r+l)//2
        ex = 0
        for i in range(n):
            need = mid // F[i]
            ex += max(0, A[i]-need)
        if ex <= k:
            r = mid
        else:
            l = mid
    print(r)

Solution (Python):
n,k = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort()
F.reverse()
t = sum(A)
ok = 10**12
ng = -1
if t <= k:
    print(0)
else:
    while abs(ok-ng) > 1:
        cur = 0
        mid = (ok+ng)//2
        for i in range(n):
            temp = mid/F[i]
            if int(temp) == temp:
                cur += max(0, int(A[i]-temp))
            else:
                if A[i]-temp > 0:
                    cur += int(A[i]-temp)+1
        if cur > k:
            ng = mid
        else:
            ok = mid
    print(ok)

Solution (Python):
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)

Solution (Python):
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)

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


def ok(x):
    need = 0
    for i in range(N):
        need += max(0, A[i] - x // F[i])
    if need <= K:
        return True
    return False


left = -1
right = 10 ** 12 + 1

while right - left > 1:
    mid = (right + left) // 2
    if ok(mid):
        right = mid
    else:
        left = mid

print(right)

Solution (Python):
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
        
        if tmp:
            r = p
        else:
            l = p + 1
    
    print(l)


if __name__ == "__main__":
    main()

Solution (Python):



def count(target):
    num=0
    for i in range(N):
        temp=target//F[i]
        num+=max(A[i]-temp,0)
    return num

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

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

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


ok=10**16+1
ng=0

if count(0)<=K:
    print(0)
    exit()


while ok-ng>1:
    mid=(ok+ng)//2
    if count(mid)>K:
        ng=mid
    else:
        ok=mid
ng=0
while ok-ng>1:
    mid=(ok+ng)//2
    if count(mid)>K:
        ng=mid
    else:
        ok=mid


print(ok)

Solution (Python):
import sys

input=sys.stdin.readline

N,K=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)

Solution (Python):

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

l, r = -1, 10 ** 12
while r - l > 1:
    x = (r + l) // 2
    
    res = 0
    for i in range(n):
        res += max(0, a[i] - x // f[i])
    
    if res > k:
        l = x
    else:
        r = x
print(r)

Solution (Python):
n, k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
Minus_A = [-x for x in A]
F = sorted(F, reverse=True)

high = 10**12
low = 0
while high - low > 1:
    mid = low + (high-low)//2
    count = 0

    for i in range(n):
        now = mid // F[i]
        count += max(A[i] - now, 0)
    
    
    
    
    if count > k:
        low = mid
    else:
        high = mid
    
ans = high

if sum(A) <= k:
    ans = 0

print(ans)

Solution (Python):
import math

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

def solve(X):
    s = 0
    for i in range(N):
        if A[i]*F[i]>X:
            s += math.ceil((A[i]*F[i]-X)/F[i])
    
    return s <= K

if sum(A) <= K:
    print(0)
else:
    l, r = 0, 10**12+10
    while l+1<r:
        mid = (l+r)//2
        if solve(mid):
            r = mid
        else:
            l = mid
    print(r)

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

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

def solve(time):
    cnt=0
    for i in range(n):
        tmp = time // f[i]
        if a[i] - tmp > 0:
            cnt += (a[i]-tmp)
    if cnt <= k:
        return True
    else:
        return False

r=0
l=0
for i in range(n):
    r=max(r,a[i]*f[i])

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

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

Solution (Python):
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:
    
    m = (l+r)//2
    if test(m):
        r=m
    else:
        l=m
if test(l):
    print(l)
else:
    print(l+1)

Solution (Python):
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

Solution (Python):

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

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

left = 0
right = 10**12
while True:
    mid = (left+right)//2
    if right - left <= 1:
        count = 0
        for i in range(N):
            a = left//F[i]
            count+=max(0,A[i]-a)
        if count <= K:
            ans = left
        else:
            ans = right
        break
    
    
    count = 0
    for i in range(N):
        a = mid//F[i]
        count+=max(0,A[i]-a)
    if count <= K:
        right = mid
    else:
        left = mid
        
        

print(ans)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
import numpy as np

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

    if sum(a) <= K:
        print(0)
    else:
        a = np.array(a)
        f = np.array(f)
        left,right = 0,max(a)*max(f)
        while right-left > 1:
            mid = (left+right)//2
            pra = a-mid//f
            pra[pra<0] = 0
            if np.sum(pra) > K:
                left = mid
            else:
                right = mid
        print(right)

if __name__ == "__main__":
    main()

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
ng=-1
ok=10**12
while ok-ng>1:
    mid=(ok+ng)//2
    temp=0
    flag=0
    for i in range(n):
        a=mid//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        ng=mid
    else:
        ok=mid

print(ok)

Solution (Python):
def main():
    import sys
    input=sys.stdin.readline
    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]

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

if __name__=='__main__':
    main()

Solution (Python):
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]


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)

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N, K = 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)
            
        if K >= k:
            r = tmp
        else:
            l = tmp
    print(r)
main()

Solution (Python):
def main():
    N, K = 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)
            
        if K >= k:
            r = tmp
        else:
            l = tmp
    print(r)


main()

Solution (Python):
import heapq
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
S = sum(A)
if S <= K:
    print(0)

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

    r = A[-1]*F[0]

    l = 0

    while(1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            k += max(0, x - (tmp // y))
        if k > K:
            l = tmp
        else:
            r = tmp

        if l+1 == r:
            print(r)
            exit(0)

Solution (Python):
n, k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

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

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

l = -1
r = 10**18
while l+1 < r:
    c = (l+r)//2
    if ok(c):
        r = c
    else:
        l = c
print(r)

Solution (Python):
def sub(x):
	global A;	global F;	global K
	s = 0
	for i in range(N):
		s += max(A[i] - x // F[i], 0)
	return s <= K

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


l = -1; r = max(A) * max(F)
while r - l > 1:
	m = (l + r) // 2
	if sub(m):
		r = m
	else:
		l = m

print(r)

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

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


def f(x):
    r = 0
    for i in range(N):
        a, f = A[i], F[i]
        m = a * f
        if m > x:
            r += (m - x + f - 1) // f
    return r

under = -1
r = 10**18
while r - under > 1:
    m = (under + r) // 2
    if f(m) > K: under = m
    else: r = m
print(r)

Solution (Python):
def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    A.sort(reverse=True)
    F.sort()

    l_score=-1
    r_score=10**12
    while l_score<r_score-1:
        t_score=(l_score+r_score)//2
        count=0
        for i in range(N):
            count+=max(0,A[i]-t_score//F[i])
        if count<=K:
            r_score=t_score
        else:
            l_score=t_score
    print(r_score)
if __name__=="__main__":
    main()

Solution (Python):
from math import ceil

N,K = map(int,input().split())
A = sorted([int(i) for i in input().split()]) 
F = sorted([int(i) for i in input().split()],reverse = True) 
cost = [a*f for a,f in zip(A,F)]




def grade_is(M:int):
    training = 0
    for i in range(N):
        if cost[i] > M:
            training += ceil((cost[i] - M) / F[i])
        if training > K:
            return False
    return True

def main():
    ok = 10 ** 18 + 1
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if grade_is(mid):
            ok = mid
        else:
            ng = mid

    print(ok)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N, K = (int(i) for i in 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 is_ok(mid):
        
        need = 0
        for i in range(N):
            if mid < A[i]*F[i]:
                b = (F[i]*A[i] - mid)
                need += (b + F[i] - 1)//F[i]
        if need <= K:
            return True
        else:
            return False

    def binary_search_meguru():
        ng = -1
        ok = 10**18 + 1
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(binary_search_meguru())


if __name__ == '__main__':
    main()

Solution (Python):
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)
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)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort()
f.reverse()
l=-1;r=max(a)*max(f)+1
sum=sum(a)
while abs(l-r)>1:
  x=(l+r)//2
  ct=0
  for i in range(n):
    ct+=max(a[i]-(x//f[i]),0)
  if ct<=k:
    r=x
  else:
    l=x
print(r)

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
left,right=-1,10**12+1
a.sort()
f.sort()

while right-left>1:
    mid=(right+left)//2
    tmp=0
    for i in range(n):
        tmp+=max(0,a[i]-mid//f[-1-i])
    
    if tmp<=k:
        right=mid
    else:
        left=mid
print(right)

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
left,right=0,10**12+1
a.sort()
f.sort()

while right-left>0:
    mid=(right+left)//2
    tmp=0
    for i in range(n):
        tmp+=max(0,a[i]-mid//f[-1-i])
    
    if tmp<=k:
        right=mid-(mid==right)
    else:
        left=mid+(mid==left)
print(right)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()
high = max(a)*max(f)
low = 0
while high > low:
  mid = (high+low)//2
  b = 0
  for i in range(n):
    b += max(a[i]-mid//f[n-i-1],0)
  if b > k:
    low = mid + (low==mid)
  else:
    high = mid - (high==mid)
mid = (high+low)//2
print(mid)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
sort_A = sorted(A)
sort_F = sorted(F,reverse=True)

def check(x):
    cnt = 0
    for i in range(N):
        tmp = x // sort_F[i]
        cnt += max(0, sort_A[i] - tmp)
    return cnt <= K



def main():
    ok = 10 ** 13
    ng = -1

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

    print(ok) 

if __name__ == "__main__":
    main()