Problem: Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The _consumption coefficient_ of Member i is A_i.  In the contest, N foods numbered 1 through N will be presented, and the _difficulty_ of Food i is F_i. The details of the contest are as follows:    * A team should assign one member to each food, and should not assign the same member to multiple foods.   * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish.   * The score of a team is the longest time it takes for an individual member to finish the food.  Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total.  What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?

Submission attempts (in order):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))



li_f = list.sort(F)
li_a = list.sort(A, reverse=True)



from operator import mul
combined1 = map(mul, li_f, li_a)



for i in range(1, K):



	n_max = combined1.index(max(combined1))




	li_a[n_max] = li_a[n_max] - 1
	ans = max(combined1)
    
print(ans)

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

li_f = list.sort(F)
li_a = list.sort(A, reverse=True)

for i in range(K + 1):
  combined1 = [x * y for (x, y) in zip(li1, li2)]
  n_max = combined1.index(max(combined1))
  li_a[n_max] = li_a[n_max] - (i - (i - 1))

print(max(combined1))

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

li_f = list.sort(F)
li_a = list.sort(A, reverse=True)

combined1 = [x * y for (x, y) in zip(li1, li2)]

for i in range(K + 1):
  n_max = combined1.index(max(combined1))
  li_a[n_max] = li_a[n_max] - (i - (i - 1))

print(max(combined1))

import numpy as np

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

new_list_f = np.array(new_list_f)
new_list_a = np.array(new_list_a)
time = new_list_f * new_list_a
 
for i in range(K + 1):
  t_max = time.index(max(time))
  new_list_a[t_max] = new_list_a[t_max] - (i - (i - 1))
  if new_list_a[t_max] == 0:
    break
  
print(time)

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 target(x):
    train_count = 0
    for i in range(N):
        a = A[i]
        targ_a = x // F[i] 
        if targ_a < a:
            train_count = train_count + a - targ_a 
    return train_count <= K　


left = -1                        
right = A[-1] * F[0]             
while right > left + 1:          
    middle = (left + right) // 2 
    if target(middle):           
        right = middle           
    
    else:                        
        left = middle            を真ん中にする（残りの左側は達成不可だから切り捨てる）

print(right)


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

li_f = list.sort(F)
li_a = list.sort(A, reverse = True)

from operator import mul
combined1 = map(mul, li_f, li_a)

for i in range(1, K):
  n_max = combined1.index(max(combined1))
  li_a[n_max] = li_a[n_max] - 1
  ans = max(combined1)
 
print(ans)

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 target(x):
    train_count = 0
    for i in range(N):
        a = A[i]
        targ_a = x // F[i] 
        if targ_a < a:
            train_count += a - targ_a
    return train_count <= K


left = -1                            
right = A[-1] * F[0]                 
while right > left+1:                
    middle = (left + right) // 2     
    if target(middle):               
        right = middle               
    else:                            
        left = middle                を真ん中にする（残りの左側は達成不可だから切り捨てる）
print(right)

import numpy as np
 
N, K = map(int, input().split())
new_list_f = sorted(list(map(int, input().split())))
new_list_a = sorted(list(map(int, input().split())), reverse=True)
 
new_list_f = np.array(new_list_f)
new_list_a = np.array(new_list_a)
time = new_list_f * new_list_a
 
for i in range(K + 1):
  t_max = time.index(max(time))
  new_list_a[t_max] = new_list_a[t_max] - (i - (i - 1))
  if new_list_a[t_max] == 0:
    break
  
print(time)

import numpy as np

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
F = [int(x) for x in input().split()]


A.sort()
F.sort(reverse=True)

A=np.array(A)
F=np.array(F)


def target(x):
    train_count = 0
    for i in range(N):
        a = A[i]
        targ_a = x // F[i] 
        if targ_a < a:
            train_count += a - targ_a
    return train_count <= K


left = -1                            
right = A[-1] * F[0]                 
while right > left+1:                
    middle = (left + right) // 2     
    if target(middle):               
        right = middle               
    else:                            
        left = middle                を真ん中にする（残りの左側は達成不可だから切り捨てる）
print(right)


import numpy as np

import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
A = np.array(input().split(), np.int64)
F = np.array(input().split(), np.int64)

A.sort()
F.sort()

F= F[::-1]

left = -1
right = (A * F).sum()
while left + 1 < right:
  middle = (left + right) // 2
  right_arr = np.maximum(0, A - middle // F).sum() <= K
  if right_arr:
    right = middle
  else:
    left = middle
print(right) 


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Time Limit Exceeded

Runtime Error

Time Limit Exceeded

Accepted