Buggy python submission (verdict: Time Limit Exceeded):
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))
AF = [A[i]*F[i] for i in range(N)]

afmax = max(AF)

def can(max_af):
  k = K
  for i in range(N):
    af = AF[i]
    if af>max_af:
      max_ai = max_af // F[i]
      k -= A[i]-max_ai
      if k<0:
        return False
  return k>=0

l = -1
r = afmax
while r-l>1:
  m = (l+r)//2
  if can(m):
    r = m
  else:
    l = m
print(r)



Fixed submission:
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))
AF = [A[i]*F[i] for i in range(N)]

afmax = max(AF)

def can(max_af):
  k = K
  for i in range(N):
    af = AF[i]
    if af>max_af:
      max_ai = max_af // F[i]
      k -= A[i]-max_ai
      if k<0:
        return False
  return k>=0

l = -1
r = afmax
while r-l>1:
  m = (l+r)//2
  if can(m):
    r = m
  else:
    l = m
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))

afmax = max([a*f for a in A for f in F])

def binsearch(cant_lower, can_upper):
  if cant_lower+1==can_upper:
    return can_upper

  m = (cant_lower + can_upper)//2

  if can(m):
    return binsearch(cant_lower, m)
  else:
    return binsearch(m, can_upper)

def can(seiseki):
  k = K
  for i in range(N):
    if A[i]*F[i]>seiseki:
      k -= math.ceil((A[i]*F[i]-seiseki)/F[i])
  return k>=0

w = binsearch(-1, afmax)
print(w)



Fixed submission:
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))
AF = [A[i]*F[i] for i in range(N)]

afmax = max(AF)

def can(max_af):
  k = K
  for i in range(N):
    af = AF[i]
    if af>max_af:
      max_ai = max_af // F[i]
      k -= A[i]-max_ai
      if k<0:
        return False
  return k>=0

l = -1
r = afmax
while r-l>1:
  m = (l+r)//2
  if can(m):
    r = m
  else:
    l = m
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))

afmax = max([a*f for a in A for f in F])

def binsearch(cant_lower, can_upper):
  if cant_lower+1==can_upper:
    return can_upper

  m = (cant_lower + can_upper)//2

  if can(m):
    return binsearch(cant_lower, m)
  else:
    return binsearch(m, can_upper)

def can(seiseki):
  k = K
  for i in range(N):
    if A[i]*F[i]>seiseki:
      k -= math.ceil((A[i]*F[i]-seiseki)/F[i])
  return k>=0

w = binsearch(-1, afmax)
print(w)



Fixed submission:
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))
AF = [A[i]*F[i] for i in range(N)]

afmax = max(AF)

def can(max_af):
  k = K
  for i in range(N):
    af = AF[i]
    if af>max_af:
      max_ai = max_af // F[i]
      k -= A[i]-max_ai
      if k<0:
        return False
  return k>=0

l = -1
r = afmax
while r-l>1:
  m = (l+r)//2
  if can(m):
    r = m
  else:
    l = m
print(r)