qyliang/CodeNanoFix huggingface dataset:
Buggy code:

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)
w=[0,0]
ans=0
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=80
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<ws/f[i]-a[i]:
            w[0]=ws
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws/f[i]
    if p>0:
        w[1]=ws
    else:
        w[0]=ws
print(w[0])

Fixed code:
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)
w=[0,0]
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=50
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<a[i]-ws//f[i]:
            p=-1
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws//f[i]
    if p>=0:
        w[1]=ws
    else:
        w[0]=ws
print(w[1])
Buggy code:
(_,K),*T=[map(int,t.split())for t in open(0)]
A,B=map(sorted,t)
m,M,i=0,2**40,1
exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K else((i+M)//2,M,i);"*41)
print(M)

Fixed code:
(_,K),*T=[map(int,t.split())for t in open(0)]
A,B=map(sorted,T)
m,M,i=0,2**40,1
exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K else((i+M)//2,M,i);"*41)
print(M)
Buggy code:
import math
N,K=map(int,input().split())
X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])]
m,M,i=0,10**12,1
exec("i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);print(m,M);"*50)
print(M)

Fixed code:
import math
N,K=map(int,input().split())
X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])]
m,M,i=0,10**12,1
exec("i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);"*50)
print(M)
Buggy code:
import math
N, K = map(int, input().split())
BCs = [b,a*b for a,b in zip(sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1])]

def f(target):
    return sum([math.ceil(max(0, c - target)/b)for b, c in BCs])<=K

if __name__ == '__main__':
    min_i, max_i, index = 0, 10**12, 1
    while True:
        if f(index):
            index, max_i = (index-1 + min_i)//2, index-1
        else:
            index, min_i = (index+1 + max_i)//2, index+1
        if min_i > max_i:
            print(min_i)
            break

Fixed code:
import math
N, K = map(int, input().split())
BCs = [(b,a*b) for a,b in zip(sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1])]

def f(target):
    return sum(math.ceil(max(0, c - target)/b)for b, c in BCs)<=K

if __name__ == '__main__':
    min_i, max_i, index = 0, 10**12, 1
    while True:
        index, max_i, min_i = ((index-1 + min_i)//2, index-1, min_i) if f(index) else ((index+1 + max_i)//2, max_i, index+1)
        if min_i > max_i:
            print(min_i)
            break
Buggy code:
import math
N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))[::-1]
Cs = [a*b for a, b in zip(As, Bs)]
BCs = list(zip(Bs, Cs))

def func(target):
    r = 0
    for b, c in BCs:
        r += math.ceil(max(0, c - target) / b)
    return r <= K

if __name__ == '__main__':
    min_i, max_i, index = 0, max(Cs)+1, 1
    while True:
        if func(index):
            index, max_i = (index-1 + min_i)//2, index-1
            continue
        index, min_i = (index+1 + max_i)//2, index+1
        if min_i == max_i:
            print(min_i)
            break

Fixed code:
import math
N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))[::-1]
Cs = [a*b for a, b in zip(As, Bs)]
BCs = list(zip(Bs, Cs))

def func(target):
    r = 0
    for b, c in BCs:
        r += math.ceil(max(0, c - target) / b)
    return r <= K

if __name__ == '__main__':
    min_i, max_i, index = 0, max(Cs)+1, 1
    while True:
        if func(index):
            index, max_i = (index-1 + min_i)//2, index-1
        else:
            index, min_i = (index+1 + max_i)//2, index+1
        if min_i > max_i:
            print(min_i)
            break
Buggy code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort(reverse=True)
f.sort()
z = zip(a,f)
ok = max(x*y for x,y in z)
ng = -1
while ok-ng>1:
  mid = (ok+ng)//2
  if sum(max(0,x-y//mid) for x,y in z) <= k:
    ok = mid
  else:
    ng = mid
print(ok)


Fixed code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort(reverse=True)
f.sort()
z = list(zip(a,f))
ok = max(x*y for x,y in z)
ng = -1
while ok-ng>1:
  mid = (ok+ng)//2
  if sum(x-mid//y for x,y in z if x*y > mid) <= k:
    ok = mid
  else:
    ng = mid
print(ok)
Buggy code:
lass Contest:
    def __init__(self, member_cost,food_cost,k):
        self.member_cost = member_cost
        self.food_cost   = food_cost
        self.max_training_times = k
        
    def canAchieve(self,target):
        sum_training_times = 0
        for i in range(len(self.member_cost)):
            sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i])

        return  sum_training_times <= self.max_training_times
        


    def bisect(self,begin,end):
        if (end - begin <= 1 ):
            return end
        target = (begin + end)//2
        if self.canAchieve(target):
            return self.bisect(begin,target)

        else:
            return self.bisect(target,end)




def resolve():
    n,k  = map(int,input().split())
    
    member_cost = list(map(int,input().split()))

    food_cost = list(map(int,input().split()))
    member_cost.sort()
    food_cost.sort(reverse=True)
    total_cost = []
    for i in range(len(member_cost)):
        total_cost.append(member_cost[i]*food_cost[i])

    max_total_cost = max(total_cost)
    contest = Contest(member_cost,food_cost,k)
    print(contest.bisect(-1,max_total_cost))
    
resolve()

Fixed code:
class Contest:
    def __init__(self, member_cost,food_cost,k):
        self.member_cost = member_cost
        self.food_cost   = food_cost
        self.max_training_times = k
        
    def canAchieve(self,target):
        sum_training_times = 0
        for i in range(len(self.member_cost)):
            sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i])

        return  sum_training_times <= self.max_training_times
        


    def bisect(self,begin,end):
        if (end - begin <= 1 ):
            return end
        target = (begin + end)//2
        if self.canAchieve(target):
            return self.bisect(begin,target)

        else:
            return self.bisect(target,end)




def resolve():
    n,k  = map(int,input().split())
    
    member_cost = list(map(int,input().split()))

    food_cost = list(map(int,input().split()))
    member_cost.sort()
    food_cost.sort(reverse=True)
    total_cost = []
    for i in range(len(member_cost)):
        total_cost.append(member_cost[i]*food_cost[i])

    max_total_cost = max(total_cost)
    contest = Contest(member_cost,food_cost,k)
    print(contest.bisect(-1,max_total_cost))
    
resolve()
Buggy code:
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=0
    right=10**12
    while True:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
        if right-left<=1:
            break
    print(right)

    '''
    while left + 1 < right:
      mid = (left+right)//2
      if can_eat(mid):
        right = mid
      else:
        left = mid
     
    answer = right
    print(answer)
    '''
    
main()

Fixed code:
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=-1
    right=10**12
    while left + 1 < right:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
    print(right)

    '''
    while left + 1 < right:
      mid = (left+right)//2
      if can_eat(mid):
        right = mid
      else:
        left = mid
     
    answer = right
    print(answer)
    '''
    
main()
Buggy code:
import numpy as np
N, K= map(int, input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]

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

lower_bound=0
upper_bound=np.max(A*F)
K_tmp=0

while upper_bound-lower_bound>0:
    mid=(lower_bound+upper_bound)//2
    K_tmp=np.sum(np.maximum(A-mid//F, 0))
    if K_tmp<K:
        upper_bound=mid
    elif K_tmp>K:
        lower_bound=mid
    elif K_tmp==K:
        break

print(mid)

Fixed code:
import numpy as np
N, K= map(int, input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]

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

lower_bound=0
upper_bound=np.max(A*F)
K_tmp=0

while upper_bound>=lower_bound:
    mid=(lower_bound+upper_bound)//2
    K_tmp=np.sum(np.maximum(A-mid//F, 0))
    if K_tmp<=K:
        upper_bound=mid-1
    else:
        lower_bound=mid+1

print(lower_bound)
Buggy code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, k = LMIIS()
    f = LMIIS()
    a = LMIIS()
    a.sort(reverse=True)
    a.sort()


    max_ = 10**12
    min_ = 0

    while max_ != min_ + 1:
        x = (max_ + min_) // 2
        shugyo = 0
        for i in range(n):
            shugyo += max(0, a[i] - x // f[i])

        if shugyo <= k:
            max_ = x
        else:
            min_ = x


    if x == min_:
        x += 1
    if sum(a) <= k:
        x = 0
    print(x)

if __name__ == '__main__':
    main()


Fixed code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, k = LMIIS()
    aa = LMIIS()
    ff = LMIIS()
    aa.sort(reverse=True)
    ff.sort()
    a = tuple(aa)
    f = tuple(ff)


    max_ = 10**12
    min_ = 0

    while max_ != min_ + 1:
        x = (max_ + min_) // 2
        shugyo = 0
        for i in range(n):
            shugyo += max(0, a[i] - x // f[i])

        if shugyo <= k:
            max_ = x
        else:
            min_ = x


    if x == min_:
        x += 1
    if sum(a) <= k:
        x = 0
    print(x)

if __name__ == '__main__':
    main()
Buggy code:
def binary_search(a, f, target, left, right):
    ans = a[-1] * f[-1]
    while left + 1 < right:
        mid = (left+right)//2
        cost = 0
        for aa,ff in zip(a,f):
            if aa - mid // ff > 0:
                cost += aa - mid // ff
        if cost > target:
            left = mid
        else:
            right = mid
    return right

n,k = map(int,input().split())
a = sorted(map(int, input().split()), reverse=True)
f = sorted(map(int, input().split()))
target = binary_search(a,f,k,0,max(a) * max(f))
mx = 0
cost = 0
for aa, ff in zip(a,f):
    if aa - target // ff > 0:
        aa = (target // ff)
        cost += aa - target // ff
    if mx < aa * ff:
        mx = aa * ff
print(mx)


Fixed code:
def binary_search(a, f, target, left, right):
    ans = a[-1] * f[-1]
    while left + 1 < right:
        mid = (left+right)//2
        cost = 0
        for aa,ff in zip(a,f):
            if ff > mid:
                cost += aa
            elif aa - mid // ff > 0:
                cost += aa - mid // ff
        if cost > target:
            left = mid
        else:
            right = mid
    return right

n,k = map(int,input().split())
a = sorted(map(int, input().split()), reverse=True)
f = sorted(map(int, input().split()))
target = binary_search(a,f,k,-1,max(a) * max(f))
mx = 0
cost = 0
for aa, ff in zip(a,f):
    if ff > target:
        cost += aa
        aa = 0
    elif aa - target // ff > 0:
        cost += aa - target // ff
        aa = (target // ff)
    if mx < aa * ff:
        mx = aa * ff
print(mx)
Buggy code:
import numpy as np

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

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

l ,r = 0, 10 ** 12
x = 0
while l <= r:
	x = (l + r) // 2
	if np.clip(a - f // x, 0, None).sum() <= k:
		l += 1
	else:
		r -= 1
print(l)

Fixed code:
import numpy as np

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

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

l ,r = 0, 10 ** 12
while l <= r:
 x = (l + r) // 2
 if np.clip(a - x // f, 0, None).sum() <= k:
  r = x - 1
 else:
  l = x + 1
print(l)
Buggy code:
import sys
import math
import bisect
 
 
sys.setrecursionlimit(1000000000)
def input():
    return sys.stdin.readline().strip()
 
def iinput():
    return int(input())
 
def finput():
    return float(input())
 
def tinput():
    return input().split()
 
def rinput():
    return map(int, tinput())
 
def rlinput():
    return list(rinput())
 
def modst(a, s):
    res = 1
    while s:
        if s % 2:
            res *= a
        a *= a
        s //= 2
    return res

 
def main():
    n, k = rinput()
    a = sorted(rlinput())
    s = sorted(rlinput())
    l, res = -1, 10 ** 12
    while res - l > 1:
        m = (res + l) // 2
        q = k    
        for i in range(n):
            w = a[- i - 1] - (m // s[- i - 1])
            q -= max(0, w)
        if q < 0:
            l = m
        else:
            res = m
    print(res)        
main()

Fixed code:
import sys
import math
import bisect
 
 
sys.setrecursionlimit(1000000000)
def input():
    return sys.stdin.readline().strip()
 
def iinput():
    return int(input())
 
def finput():
    return float(input())
 
def tinput():
    return input().split()
 
def rinput():
    return map(int, tinput())
 
def rlinput():
    return list(rinput())
 
def modst(a, s):
    res = 1
    while s:
        if s % 2:
            res *= a
        a *= a
        s //= 2
    return res

 
def main():
    n, k = rinput()
    a = sorted(rlinput())
    s = sorted(rlinput())
    l, res = -1, 10 ** 12
    while res - l > 1:
        m = (res + l) // 2
        q = k    
        for i in range(n):
            w = a[i] - (m // s[- i - 1])
            q -= max(0, w)
        if q < 0:
            l = m
        else:
            res = m
    print(res)        
main()
Buggy code:
import sys
import heapq


def can_eat_with_score(key):
    now_K = K
    for i, now_score in enumerate(score):
        if key < now_score:
            now_K -= (key-now_score+F[i]-1) // F[i]
            if now_K < 0:
                return False
    return True

input = sys.stdin.readline

priority_que = []
N, K = map(int, input().split())
A = sorted(map(int, input().strip().split()))
F = sorted(map(int, input().strip().split()))[::-1]
score = [A[i]*F[i] for i in range(N)]
if sum(A) <= K:
    print(0)
    exit()

max_score = max(score)
now_border = max_score // 2
left = -1
right = max_score
while left - right > 1:
    can_eat = can_eat_with_score((left+right)//2)
    if can_eat:
        right = (left+right)//2
    else:
        left = (left+right)//2
print(left+1)


Fixed code:
import sys
import heapq


def can_eat_with_score(key):
    now_K = K
    for i, now_score in enumerate(score):
        if key < now_score:
            now_K -= (now_score-key+F[i]-1) // F[i]
            if now_K < 0:
                return False
    return True


input = sys.stdin.readline

priority_que = []
N, K = map(int, input().split())
A = sorted(map(int, input().strip().split()))
F = sorted(map(int, input().strip().split()))[::-1]
score = [A[i]*F[i] for i in range(N)]
if sum(A) <= K:
    print("0")
    exit()


left = -1
right = max(score)
while right - left > 1:
    mid = (left+right) // 2
    can_eat = can_eat_with_score(mid)
    # print(mid, can_eat)
    if can_eat:
        right = mid
    else:
        left = mid
print(left+1)
Buggy code:
n,k=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(m,a[i]*f[i])
x=m//2
l=0
r=m
def check(x):
    p=0
    for i in range(n):
        if x//f[i]<a[i]:
            p+=a[i]-x//f[i]
    if p>k:
        return False
    else:
        return True
while 1<r-l:
    if check(x):
        r=x
        x=(r-l)//2
    else:
        l=x
        x=(r-l)//2
print(r)

Fixed code:
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 = 0
r = max(a) * max(f)

def check(x):
    tot = 0
    for i in range(n):
        need = a[i] - x // f[i]
        tot += need if need >= 0 else 0
    return tot <= k


while l < r:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m+1

print(r)
Buggy code:
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 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)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 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)

Fixed code:
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 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)
Buggy code:
k,*t=[map(int,t.split())for t in open(0)]
A,F=map(sorted,t)
o=10**12
g=-1
while~g+o:
 m,l=o+g>>1,k[1]
 for a,f in zip(A,F[::-1]):l-=max(0,a-m//f)
 if l<0:g=m
 else:o=m
print(o)

Fixed code:
(_,k),*t=[map(int,t.split())for t in open(0)]
A,F=map(sorted,t)
o=10**12
g=-1
while o-g>1:
 m,l=o+g>>1,k
 for a,f in zip(A,F[::-1]):l-=max(0,a-m//f)
 if l<0:g=m
 else:o=m
print(o)
Buggy code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

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

print(left)


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

right = 0
left = a[-1]*f[0]

while right!=left:
    mid = (right+left)//2
    syu = 0
    
    for i in range(n):
        if a[i]*f[i]>mid:
            syu += a[i] - mid//f[i]
    
    if syu <= k:
        left = mid
    else:
        right = mid + 1
        
print(right)
Buggy code:
n, k = 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 isok(ans):
    k_ = 0
    for a,f in zip(A,F):
        if a > ans//f:
            k_ += a - ans//f
            if k_ > k:
                return False
    return True

ok = 10**12+1
ng = 0

while ok-ng > 1:
    m = (ok+ng)//2
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)

Fixed code:
n, k = 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 isok(ans):
    k_ = 0
    for a,f in zip(A,F):
        if a > ans//f:
            k_ += a - ans//f
            if k_ > k:
                return False
    return True

ok = max(A)*max(F)
ng = 0

while ok - ng >= 1:
    m = (ok+ng)//2
    if ok - ng == 1:
        if isok(ng):
            ok = ng
            break
        break
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)
Buggy code:
import numpy as np

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

Asum = sum(A)

Asort = sorted(A)
Fsort = sorted(F,reverse=True)

def test(x):
    res = max(0,Asort-x//Fsort).sum()
    return res <= K

left = -1
right = 10**13

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

ans = right

print(ans)



Fixed code:
import numpy as np

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

Asum = sum(A)

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

def test(x):
    res = np.maximum(0,Asort-x//Fsort).sum()
    return res <= K

left = -1
right = 10**13

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

ans = right

print(ans)
Buggy code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
import numpy as np
s_A = sum(A)
if s_A<=K:
  print(0)
  
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)
mi=0
ma=max(F)*max(A)
while mi+1<ma:
  mid = (mi+ma)//2
  print(ma)
  if s_A-np.minimum(A,mid//F).sum()<=K:
    ma=mid
  else:
    mi=mid
  
print(ma)

Fixed code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
import numpy as np
s_A = sum(A)
if s_A<=K:
  print(0)

else:
  A.sort()
  F.sort(reverse=True)
  A = np.array(A)
  F = np.array(F)
  mi=0
  ma=max(F)*max(A)
  while mi+1<ma:
    mid = (mi+ma)//2
    if s_A-np.minimum(A,mid//F).sum()<=K:
      ma=mid
    else:
      mi=mid

  print(ma)