def main():

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

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

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

    A.sort(reverse=True)

    F.sort()



    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()
from sys import stdin

import numpy as np

def main():

    #入力

    readline=stdin.readline

    n,k=list(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)



if __name__=="__main__":

    main()
def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse=True)
    F.sort()
    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()

from sys import stdin
import numpy as np


def main():
    # 入力
    readline = stdin.readline
    n, k = list(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)


if __name__ == "__main__":
    main()

+from sys import stdin +import numpy as np + + -    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() -    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 +    # 入力 +    readline = stdin.readline +    n, k = list(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 -            l_score = t_score -    print(r_score) +            l = x +    print(r)