qyliang/CodeNanoFix huggingface dataset:
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)

ok = 10000000
ng = 0

while ok-ng>1:
    mid = ng + (ok-ng)//2
    trainings = 0
    for i in range(N):
        t = A[i]-mid//F[i]
        if t > 0:
            trainings += t
    if trainings <= 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()
F.sort(reverse=True)

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

while ok-ng>1:
    mid = ng + (ok-ng)//2
    trainings = 0
    for i in range(N):
        t = A[i]-mid//F[i]
        if t > 0:
            trainings += t
    if trainings <= K:
        ok = mid
    else:
        ng = mid
trainings = 0
for i in range(N):
    t = A[i]-ng//F[i]
    if t>0:
        trainings += t
if trainings<=K:
    print(ng)
else:
    print(ok)
Buggy code:
from math import ceil
def chk(A, C, x, K):
    cnt = 0
    for i in range(N):
        cnt += max(ceil(A[i]-x/C[i]), 0)
        if cnt > K:
            return False
    return True
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort(reverse=True)
    C.sort()
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(A, C, m, K):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()

Fixed code:
from math import ceil
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort(reverse=True)
    C.sort()
    def chk(x):
        cnt = 0
        for i in range(N):
            cnt += max(ceil(A[i]-x/C[i]), 0)
            if cnt > K:
                return False
        return True
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(m):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()
Buggy code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
lot = []
for k in range(N):
  lot.append((A[k]*F[k], k))
lot.sort(key =  lambda x:x[0],reverse=True)
high = lot[0][0]
#print('A:', A)
#print('F:', F)
#print(lot)
def binary_search(high):
  low = 0
  mid = (low + high) //2
  while low < high:
    final = False
    mid = (low + high) //2
    if low == high-1:
      final = True
    #print(low, high, mid)
    res = K
    flag = True
    for k in range(N):
      if res < 0:
        flag = False
        break
      else:
        if lot[k][0] <= mid:
          break
        else:
          res -= ceil((lot[k][0]-mid)/F[lot[k][1]])
          continue
    #print(flag)
    if flag:
      high = mid
    else:
      if final:
        mid += 1
      low = mid
    #print(low, high, mid)
  #return None
  return mid

print(binary_search(high))

Fixed code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
lot = []
for k in range(N):
  lot.append((A[k]*F[k], k))
lot.sort(key =  lambda x:x[0],reverse=True)
high = lot[0][0]
#print('A:', A)
#print('F:', F)
#rint(lot)
def binary_search(high):
  low = 0
  mid = (low + high) //2
  while low < high:
    final = False
    mid = (low + high) //2
    #print(low, high, mid)
    if low == high-1:
      final = True
    #print(low, high, mid)
    res = K
    flag = True
    for k in range(N):
      if res < 0:
        break
      else:
        if lot[k][0] <= mid:
          break
        else:
          res -= ceil((lot[k][0]-mid)/F[lot[k][1]])
          continue
    if res < 0:
      flag = False
    #print(flag)
    if flag:
      high = mid
    else:
      if final:
        mid += 1
      low = mid
    #print(low, high, mid)
  #return None
  return mid

print(binary_search(high))
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 check(x):
  r = 0
  for i in range(n):
    r += (a[i]*f[i]-x+(f[i]-1))//f[i]
  if r<=k:
    return True
  else:
    return False
ok = 10**12
ng = 0
while ok-ng>1:
  mid = (ok + ng)//2
  if check(mid):
    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()
f.sort(reverse = True)
af = [a[i]*f[i] for i in range(n)]

def check(x):
  r = 0
  for i in range(n):
    r += (max(0,(af[i]-x))+f[i]-1)//f[i]
  #print(r, x)
  if r<=k:
    return True
  else:
    return False
ok = 10**12+1
ng = -1
while ok-ng>1:
  mid = (ok + ng)//2
  if check(mid):
    ok = mid
  else:
    ng = mid
print(ok)
Buggy code:
from math import ceil
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)

left=0
right=10**12+1
ans=float("INF")
while True:
    mid=(left+right)//2
    if mid==left or mid==right:
        break
    now=0
    for i in range(N):
        if F[i]*A[i]>mid:
            now+=ceil(((F[i]*A[i])-mid)/F[i])
    #print(now, mid)
    if now==K:
        ans=min(ans, mid)
        break
    elif now>K:
        left=mid
    else:
        right=mid
        ans=min(ans, mid)

print(ans)

Fixed code:
from math import ceil
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)

left=0
right=10**12+1
ans=float("INF")
while True:
    mid=(left+right)//2

    now=0
    for i in range(N):
        if F[i]*A[i]>mid:
            now+=ceil(((F[i]*A[i])-mid)/F[i])
    #print(now, mid)
    if now==K:
        ans=min(ans, mid)
        if right==mid:
            break
        right=mid
    elif now>K:
        if left==mid:
            break
        left=mid
    else:
        if right==mid:
            break
        right=mid
        ans=min(ans, mid)

print(ans)
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)
print(A)
print(F)
la = 10**12+1
sm = -1
while sm+1<la:
    mi = (sm+la)//2
    y=0
    for i in range(N):
        y += max(0, A[i]-(mi//F[i]))
    if y<=K:
        la = mi
    else:
        sm = mi
print(la)

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)

la = 10**12+1
sm = -1
while sm+1<la:
    mi = (sm+la)//2
    y=0
    for i in range(N):
        y += max(0, A[i]-(mi//F[i]))
    if y<=K:
        la = mi
    else:
        sm = mi
print(la)
Buggy code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    worst_score = 10 ** 12

    n, k = ns()
    a = na()
    f = na()
    a.sort()
    f.sort(reverse=True)
    score = [ai * fi for ai, fi in zip(a, f)]

    l = -1
    r = worst_score + 1

    while r - l > 1:
        middle = (l + r) // 2
        tmp_k = k
        for i in range(n):
            tmp = math.ceil((score[i] - middle) // f[i])
            tmp_k -= max(0, tmp)

            if tmp_k < 0:
                break

        if tmp_k >= 0:
            r = middle
        else:
            l = middle
            
    print(r)


if __name__ == '__main__':
    main()


Fixed code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    worst_score = 10 ** 12

    n, k = ns()
    a = na()
    f = na()
    a.sort()
    f.sort(reverse=True)
    score = [ai * fi for ai, fi in zip(a, f)]

    l = 0
    r = worst_score

    while True:
        middle = (l + r) // 2

        tmp_k = k
        for i in range(n):
            tmp = (score[i] - middle + f[i] - 1) // f[i]
            tmp_k -= max(0, tmp)

            if tmp_k < 0:
                break

        if r - l == 1:
            print(middle if tmp_k >= 0 else middle + 1)
            exit(0)

        if tmp_k < 0:
            l = middle
        else:
            r = middle





if __name__ == '__main__':
    main()
Buggy code:
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)
    exit()

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:
        break
    if ck_sum > k:
        lb = x
    else:
        ub = x
a_ck = a - ck
ans = a_ck * f
print(max(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()))

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

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)
Buggy code:
n,k = map(int, input().split())
al = list(map(int, input().split()))
fl = list(map(int, input().split()))

al.sort()
fl.sort(reverse=True)
afl = []
for a,f in zip(al,fl):
    afl.append((a,f))

ok, ng = 10**12, 0
while abs(ok-ng) > 1:
    mid = (ok+ng) // 2
    cnt = 0
    for a,f in afl:
        val = a*f
        train_cnt = (val-mid-1)//f + 1
        cnt += max(train_cnt, 0)

    if cnt <= k:
        ok = mid
    else:
    	ng = mid
print(ok)

Fixed code:
n,k = map(int, input().split())
al = list(map(int, input().split()))
fl = list(map(int, input().split()))

al.sort()
fl.sort(reverse=True)
afl = []
for a,f in zip(al,fl):
    afl.append((a,f))

ok, ng = 10**12, -1
while abs(ok-ng) > 1:
    mid = (ok+ng) // 2
    cnt = 0
    for a,f in afl:
        val = a*f
        train_cnt = (val-mid-1)//f + 1
        cnt += max(train_cnt, 0)

    if cnt <= k:
        ok = mid
    else:
    	ng = mid
print(ok)
Buggy code:
import copy
from heapq import heappop, heapify, heappush
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]
ans = 0
A.sort(reverse=True)
F.sort()
s = []
for i in range(N):
    s.append([A[i]*F[i], A[i], F[i]])
s.sort(reverse=True, key=lambda x: x[0])

def f(l, T):
    cur = 0
    num = 0
    S = copy.deepcopy(l)
    while cur <= K:
        if len(S) == 0:
            break
        a, b, c = S[num]
        a = -a
        if a <= T:
            break
        cur += math.ceil((a - T)/c)
        num += 1
    if cur <= K:
        return True
    else:
        return False

ok, ng = -s[0][0], -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if f(s, mid) == True:
        ok = mid
    else:
        ng = mid
print(ok)

Fixed code:
def main():
    import copy
    from heapq import heappop, heapify, heappush
    import math
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    F = [int(i) for i in input().split()]
    ans = 0
    A.sort(reverse=True)
    F.sort()
    s = []
    for i in range(N):
        s.append([A[i]*F[i], A[i], F[i]])
    s.sort(reverse=True, key=lambda x: x[0])

    def f(S, T):
        cur = 0
        num = 0
        while cur <= K:
            if num == N:
                break
            a, b, c = S[num]
            if a <= T:
                break
            cur += math.ceil((a - T)/c)
            num += 1
        if cur <= K:
            return True
        else:
            return False

    ok, ng = s[0][0], -1
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if f(s, mid) == True:
            ok = mid
        else:
            ng = mid
    print(ok)

if __name__ == '__main__':
    main()
Buggy code:
from numba import njit

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

@njit
def cond(x):
    k = 0
    for a, f in zip(A, F): k += max(a - (x // f), 0)
    return True if k <= K else False 

MIN = -1
MAX = 10**12 + 1
left, right = MIN, MAX # search range
while right - left > 1:
    mid = (left + right) // 2
    if cond(mid): right = mid
    else: left = mid
print(right)

Fixed code:
N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A, F = sorted(A), sorted(F, reverse=True)

def cond(x):
    k = 0
    for a, f in zip(A, F): k += max(a - (x // f), 0)
    return True if k <= K else False 

MIN = -1
MAX = 10**12 + 1
left, right = MIN, MAX # search range
while right - left > 1:
    mid = (left + right) // 2
    if cond(mid): right = mid
    else: left = mid
print(right)
Buggy code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()

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

point = []
for i in range(n):
    point.append(a_list[i] * f_list[i])

import math
def binary_search(point, k):
    left = 0
    right = 10 ** 12
    while left + 1< right:
        ans = 0
        center = (left + right) // 2
        for i in range(n):
            if point[i] > center:
                ans += a_list[i] - (center // f_list[i])
        if ans <= k:
            right = center
        else:
            left = center
    return center
    
value = binary_search(point, k)
print(value)


Fixed code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()

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

point = []
for i in range(n):
    point.append(a_list[i] * f_list[i])

import math
def binary_search(point, k):
    left = 0
    right = 10 ** 12
    while left + 1< right:
        ans = 0
        center = (left + right) // 2
        for i in range(n):
            if point[i] > center:
                ans += a_list[i] - (center // f_list[i])
        if ans <= k:
            right = center
        else:
            left = center
    return right    
    
value = binary_search(point, k)
print(value)
Buggy code:
N, K = map(int, input().split())
A_array = list(map(int, input().split()))
F_array = list(map(int, input().split()))

A_array.sort()
F_array.sort()
F_array = F_array[::-1]

X = 0
Y = 10 ** 12

while(Y - X > 1):
    mid = (X + Y) // 2
    # print(X, Y)
    k = 0
    for a, f in zip(A_array, F_array):
        m = mid // f
        # print(a, f, k)
        k += max(0, a - m)
    if k <= K:
        Y = mid
    else:
        X = mid

print(Y)


Fixed code:
N, K = map(int, input().split())
A_array = list(map(int, input().split()))
F_array = list(map(int, input().split()))

A_array.sort()
F_array.sort()
F_array = F_array[::-1]

X = 0
Y = 10 ** 12

while(Y - X > 0):
    mid = (X + Y) // 2
    k = 0
    for a, f in zip(A_array, F_array):
        m = mid // f
        # print(a, f, k)
        k += max(0, a - m)
    if k <= K:
        Y = mid
    else:
        if Y - X == 1:
            break
        X = mid

print(Y)
Buggy code:
N,K=[int(s) for s in input().split()]
A=[int(s) for s in input().split()]
F=[int(s) for s in input().split()]
A.sort()
F.sort(reverse=1)
print(A)
print(F)

def success(x):
  suc_sum=0
  for i in range(N):
    a=x//F[i]
    if A[i]>a:
      suc_sum+=A[i]-a
  if suc_sum<=K:
    return True
  else:
    return False

def bisearch():
  bi_max=10**12
  bi_a=0
  bi_b=bi_max
  while bi_b-bi_a>1:
    c=(bi_a+bi_b)//2
    if success(c):
      bi_a,bi_b=[bi_a,c]
    else:
      bi_a,bi_b=[c,bi_b]
  return [bi_a,bi_b]

a,b=bisearch()
print(b)    

Fixed code:
N,K=[int(s) for s in input().split()]
A=[int(s) for s in input().split()]
F=[int(s) for s in input().split()]
A.sort()
F.sort(reverse=1)


def success(x):
  suc_sum=0
  for i in range(N):
    a=x//F[i]
    if A[i]>a:
      suc_sum+=A[i]-a
  if suc_sum<=K:
    return True
  else:
    return False

def bisearch():
  bi_max=10**12
  bi_a=0
  bi_b=bi_max
  while bi_b-bi_a>1:
    c=(bi_a+bi_b)//2
    if success(c):
      bi_a,bi_b=[bi_a,c]
    else:
      bi_a,bi_b=[c,bi_b]
  return [bi_a,bi_b]

a,b=bisearch()
if success(a):
  print(a)
else:
  print(b)
Buggy code:
import math

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()
A.sort()
F.sort(reverse=True)

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

while r-l > 1:
  print(l,r)
  m = (l+r)//2

  k = 0
  for i in range(N):
    a,f = A[i], F[i]
    k += max(0, math.ceil(a-(m/f)))

  if k <= K:
    r = m
  else:
    l = m

print(r)

Fixed code:
import math

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()
A.sort()
F.sort(reverse=True)

l,r = -1,10**12+1

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

  k = 0
  for i in range(N):
    a,f = A[i], F[i]
    k += max(0,a-(m//f))

  if k <= K:
    r = m
  else:
    l = m

print(r)
Buggy code:
import numpy as np

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

Asum = sum(A)

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

l = -1
r = 10**13

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

ans = r
print(ans)


Fixed code:
import numpy as np

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


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


ub = 10**12
lb = 0

for i in range(50):
    x = (ub+lb)/2
    if judge(x):
        ub = x
    else:
        lb = x

print(int(x))


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


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


ub = 10**12
lb = -1

while lb + 1 < ub:
    x = (ub+lb)/2
    if judge(x):
        ub = x
    else:
        lb = x

print(int(ub))
Buggy code:
#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)
    np.sort(a)
    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()

Fixed code:
#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)

if __name__ == '__main__':
    main()
Buggy code:
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 -1
    else:
        l = mid 

print(l)

Fixed code:
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)
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 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)

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)

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)
Buggy code:
def check(N_:int,S_:list,F_:list,upper:int,K_:int)->bool:
    #A_i > A_j (i < j)
    cnt = 0
    for i in range(N_):
        s = S_[i]
        if s > upper:
            cnt += ceil((s - upper)/F_[i])
            if cnt > K_:
                return False
        else:
            return True
    return True


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()
    S = [f*a for f,a in zip(F,A)]
    right = sum(S)
    left = -1
    while left + 1 < right:
        mid = (right + left) // 2
        if mid == right:
            break
        if check(N,S,F,mid,K):
            right = mid
        else:
            left = mid + 1
    print(mid)
    return

if __name__ == "__main__":
    main()

Fixed code:
from math import ceil

def check(N_:int,S_:list,F_:list,upper:int,K_:int)->bool:
    #A_i > A_j (i < j)
    cnt = 0
    for i in range(N_):
        s = S_[i]
        if s > upper:
            cnt += ceil((s - upper)/F_[i])
            if cnt > K_:
                return False
    return True


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()
    S = [f*a for f,a in zip(F,A)]
    right = max(S)
    left = -1
    while left + 1 < right:
        mid = (right + left) // 2
        if mid == right:
            break
        if check(N,S,F,mid,K):
            right = mid
        else:
            left = mid
    print(right)
    return

if __name__ == "__main__":
    main()