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

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

goal_max=10**12+1
goal_min=0-1

while(goal_max-goal_min!=1):
   goal=(goal_max+goal_min)//2
   counter=0

   for i in range(N):
      counter+=max(0,A[i]-goal//F[i])

   if(counter<=K):
      goal_max=goal

   else:
      goal_min=goal
      
print(goal_max)

Fixed submission:
N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

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

goal_max=10**12+1
goal_min=0-1

while(goal_max-goal_min!=1):
   goal=(goal_max+goal_min)//2
   counter=0

   for i in range(N):
      counter+=max(0,A[i]-goal//F[i])

   if(counter<=K):
      goal_max=goal

   else:
      goal_min=goal
      
print(goal_max)

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

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

goal_max=max(time)
goal_min=0
goal=int((goal_max+goal_min)/2)

col={"-1":"NG"}
for i in range(goal_max+1):
   col[str(i)]=None

flag=True

while(flag):
   counter=0
   for i in range(N):
      counter+=(A[i]-int(goal/F[i]))

   if(counter<=K):
      if col[str(goal-1)]=="NG":
         print(goal)
         flag=False
      else:
         col[str(goal)]="OK"
         goal_max=goal
         goal=int((goal_max+goal_min)/2)

   elif(counter>K):
      if col[str(goal+1)]=="OK":
         print(goal+1)
         flag=False
      else:
         col[str(goal)]="NG"
         goal_min=goal
         goal=int((goal_max+goal_min)/2)

Fixed submission:
N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

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

goal_max=10**12+1
goal_min=0-1

while(goal_max-goal_min!=1):
   goal=(goal_max+goal_min)//2
   counter=0

   for i in range(N):
      counter+=max(0,A[i]-goal//F[i])

   if(counter<=K):
      goal_max=goal

   else:
      goal_min=goal
      
print(goal_max)

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

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

while(K>0):
   cmax=max(time)
   if(cmax>0):
      A[time.index(cmax)]-=1
      time[time.index(cmax)]=A[time.index(cmax)]*F[time.index(cmax)]
      K-=1
   elif(cmax==0):
      break

cmax=max(time)
print(cmax)

Fixed submission:
N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

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

goal_max=10**12+1
goal_min=0-1

while(goal_max-goal_min!=1):
   goal=(goal_max+goal_min)//2
   counter=0

   for i in range(N):
      counter+=max(0,A[i]-goal//F[i])

   if(counter<=K):
      goal_max=goal

   else:
      goal_min=goal
      
print(goal_max)

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

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

while(K>0):
   cmax=max(time)
   if(cmax>0):
      A[time.index(cmax)]-=1
      time[time.index(cmax)]=A[time.index(cmax)]*F[time.index(cmax)]
      K-=1
   elif(cmax==0):
      break

cmax=max(time)
print(cmax)

Fixed submission:
N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

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

goal_max=10**12+1
goal_min=0-1

while(goal_max-goal_min!=1):
   goal=(goal_max+goal_min)//2
   counter=0

   for i in range(N):
      counter+=max(0,A[i]-goal//F[i])

   if(counter<=K):
      goal_max=goal

   else:
      goal_min=goal
      
print(goal_max)

Buggy python submission (verdict: Runtime Error):
N,K=input().split()
A=list(map(int,input().split()))
F=list(map(int,input().split()))

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

while(K>0):
   cmax=max(time)
   if(cmax>0):
      A[time.index(cmax)]-=1
      time[time.index(cmax)]=A[time.index(cmax)]*F[time.index(cmax)]
      K-=1
   elif(cmax=0):
      break

cmax=max(time)
print(cmax)


Fixed submission:
N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

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

goal_max=10**12+1
goal_min=0-1

while(goal_max-goal_min!=1):
   goal=(goal_max+goal_min)//2
   counter=0

   for i in range(N):
      counter+=max(0,A[i]-goal//F[i])

   if(counter<=K):
      goal_max=goal

   else:
      goal_min=goal
      
print(goal_max)