Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if sum(max(A[i]-xm//F[i] ,0) for i in range(0,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)            


Fixed submission:
import numpy as np

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

Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        AF = A-xm//F 
        if np.sum(AF[AF>0]) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
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 = np.sort(A)
F = np.sort(F)[::-1]
Amax = A[-1]
Fmax = F[0]
x=0

if np.sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if np.sum(np.max(A[i]-xm//F[i] ,0) for i in range(0,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)            


Fixed submission:
import numpy as np

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

Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        AF = A-xm//F 
        if np.sum(AF[AF>0]) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
Al = list(map(int,input().split()))
Fl = list(map(int,input().split()))

A = tuple(sorted(Al))
F = tuple(sorted(Fl,reverse = True))
Amax = A[-1]
Fmax = F[0]
x=0

def maxA2(AA, FF, NN):
    i=0
    while i < NN:
        yield max(A[i]-xm//F[i] ,0)
        i += 1


if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if sum(maxA2(A,F,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)            


Fixed submission:
import numpy as np

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

Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        AF = A-xm//F 
        if np.sum(AF[AF>0]) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
Al = list(map(int,input().split()))
Fl = list(map(int,input().split()))

A = tuple(sorted(Al))
F = tuple(sorted(Fl,reverse = True))
Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if sum(max(A[i]-xm//F[i] ,0) for i in range(0,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)            


Fixed submission:
import numpy as np

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

Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        AF = A-xm//F 
        if np.sum(AF[AF>0]) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse = True)
Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if sum(max(A[i]-xm//F[i] ,0) for i in range(0,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)            


Fixed submission:
import numpy as np

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

Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        AF = A-xm//F 
        if np.sum(AF[AF>0]) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse = True)
Amax = A[-1]
Fmax = F[0]
As = sum(a for a in A)

x=0
if As > K:
    x1 = 0
    x2 = Amax*Fmax
    while True:
        Asum1 = Asum2 = 0
        for i in range(0,N):
            if x1//F[i] > A[i]:
                if x1<x2:
                    x1 += 1
                    break
            else:
                Asum1 += x1//F[i]
                Asum2 += x2//F[i]
        else:
            if As-Asum1 > K and As-Asum2 <= K:  #x1-NG and x2-OK
                if x1+1==x2:    #0,1,...,x1,x2,...  Xmin=x2
                    x = x2
                    break
                else:       #0,1,...x1,x1+1,...,x2-1,x2,... 
                    x2b = x2
                    x2 = int((x1+x2)//2)
                    continue
            elif As-Asum1 > K and As-Asum2 > K:   #x1-NG and x2-NG
                x1 = x2
                x2 = int((x2+x2b)//2)
                if x1 == x2:
                    x2 += 1
                    continue
print(x)            


Fixed submission:
import numpy as np

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

Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        AF = A-xm//F 
        if np.sum(AF[AF>0]) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)