Problem:


Score: 500 points

Problem Statement

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?

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^{18}

1 \leq A_i \leq 10^6\ (1 \leq i \leq N)

1 \leq F_i \leq 10^6\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N
F_1 F_2 ... F_N

Output

Print the minimum possible score of the team.

Sample Input 1

3 5
4 2 1
2 3 1

Sample Output 1

2

They can achieve the score of 2, as follows:

Member 1 does 4 sets of training and eats Food 2 in (4-4) \times 3 = 0 seconds.

Member 2 does 1 set of training and eats Food 3 in (2-1) \times 1 = 1 second.

Member 3 does 0 sets of training and eats Food 1 in (1-0) \times 2 = 2 seconds.

They cannot achieve a score of less than 2, so the answer is 2.

Sample Input 2

3 8
4 2 1
2 3 1

Sample Output 2

0

They can choose not to do exactly K sets of training.

Sample Input 3

11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2

Sample Output 3

12



Sample input:
3 5
4 2 1
2 3 1


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
readline = sys.stdin.buffer.readline

N,K = map(int,readline().split())
people = np.array(readline().split(),np.int64)
food = np.array(readline().split(),np.int64)
 
people.sort()
food.sort()
food=food[::-1]

#2分探索　Kの値で
_max = max(people)*max(food)
_min = 0

while _max>_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  K_arr = np.maximum(0,people - mean//food)
  # 総修行回数
  _K = sum(K_arr)
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
readline = sys.stdin.buffer.readline

N,K = map(int,readline().split())
people = np.array(readline().split(),np.int64)
food = np.array(readline().split(),np.int64)
 
people.sort()
food.sort()
food=food[::-1]

#2分探索　Kの値で
_max = 10**12
_min = 0

while _max>_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  K_arr = np.maximum(0,people - mean//food)
  # 総修行回数
  _K = sum(K_arr)
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
readline = sys.stdin.buffer.readline

N,K = map(int,readline().split())
people = np.array(readline().split(),np.int64)
food = np.array(readline().split(),np.int64)
 
people.sort()
food.sort()
food=food[::-1]

#2分探索　Kの値で
_max = 10**12
_min = 0

while _max!=_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  K_arr = np.maximum(0,people - mean//food)
  # 総修行回数
  _K = sum(K_arr)
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = map(int,input().split())
people = np.array(sorted(list(map(int,input().split()))))
food = np.array(sorted(list(map(int,input().split())))[::-1])


#2分探索　Kの値で
_max = 10**12
_min = 0

while _max!=_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  K_arr = np.maximum(0,people - mean//food)
  # 総修行回数
  _K = sum(K_arr)
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = map(int,input().split())
people = np.array(sorted(list(map(int,input().split()))))
food = np.array(sorted(list(map(int,input().split())))[::-1])


#2分探索　Kの値で
_max = 10**12
_min = 0

while _max!=_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  K_arr = people - mean//food
  K_arr = K_arr[K_arr>0]
  # 総修行回数
  _K = sum(K_arr)
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = map(int,input().split())
people = np.array(sorted(list(map(int,input().split()))))
food = np.array(sorted(list(map(int,input().split())))[::-1])


#2分探索　Kの値で
_max = 10**12
_min = 0

while _max!=_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  K_arr = people - mean//food
  K_arr = [k for k in list(K_arr) if k>0]
  # 総修行回数
  _K = sum(K_arr)
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# coding: utf-8

# 整数 > 整数型
def I(): return int(input())

# 整数列 '1 2 3 4' > 整数型リスト
def IsIl(): return list(map(lambda x: int(x), input().split()))

# 改行挟む整数列　'1/n 2/n 3/n' > 整数型りすと
def InIl(n): return [input() for i in range(n)]

# 整数列 '1 2' > 整数型タプル
def IsIt(): return map(lambda x: int(x), input().split())

# 改行挟む整数列　'1\n 2\n 3\n' > 整数型たぷる
def InIl(n): return map(input() for i in range(n))

# 文字列 'abcd' > 文字型リスト
def SsSl(): return list(map(lambda x: x, input()))

# 整数 '1234' > 整数型リスト

# 文字列 'aba' > 辞書（文字型:個数）{'a':2,'b':1}
def SSd():
    from collections import defaultdict
    A = input() # [int(i) for i in input().split()]
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

import sys

n,k=IsIt()

a = sorted(IsIt())
f = sorted(IsIt(),reverse=True)

af = []
for i in range(n):
    af.append(a[i]*f[i])

counter = 0
for i_k in range(k):
    max_af = max(af)
    for i_num, i_af in enumerate(af):
        if i_af == max_af:
            counter += 1
            af[i_num] -= f[i_num]
            if counter >= k:
                print(max(af))
                sys.exit()
            if max_af != max(af):
                break
                
    
    

print(max(af))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# coding: utf-8

# 整数 > 整数型
def I(): return int(input())

# 整数列 '1 2 3 4' > 整数型リスト
def IsIl(): return list(map(lambda x: int(x), input().split()))

# 改行挟む整数列　'1/n 2/n 3/n' > 整数型りすと
def InIl(n): return [input() for i in range(n)]

# 整数列 '1 2' > 整数型タプル
def IsIt(): return map(lambda x: int(x), input().split())

# 改行挟む整数列　'1\n 2\n 3\n' > 整数型たぷる
def InIl(n): return map(input() for i in range(n))

# 文字列 'abcd' > 文字型リスト
def SsSl(): return list(map(lambda x: x, input()))

# 整数 '1234' > 整数型リスト

# 文字列 'aba' > 辞書（文字型:個数）{'a':2,'b':1}
def SSd():
    from collections import defaultdict
    A = input() # [int(i) for i in input().split()]
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

import sys

n,k=IsIt()

a = sorted(IsIt())
f = sorted(IsIt(),reverse=True)

af = []
for i in range(n):
    af.append(a[i]*f[i])

counter = 0
for i_k in range(k):
    max_af = max(af)
    for i_num, i_af in enumerate(af):
        if i_af == max_af:
            counter += 1
            af[i_num] -= f[i_num]
            if counter >= k:
                print(max(af))
                sys.exit()
    
    

print(max(af))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort(reverse=True)
f.sort()
a=np.array(a)
f=np.array(f)
t=a*f.T
for i in range(k):
    t_mx=np.argmax(t)
    t[t_mx]=t[t_mx]-f[t_mx]
    
if np.min(a)<=0:
    print(0)
else:
    t_mx=np.max(t)
    print(t_mx)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, k = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
F = [int(x) for x in input().split()]

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

while k > -1:
    time = []
    for i in range(n):
        time.append([A[i]*F[i], i, A[i], F[i]])
    #print(time)
    max_time = max(time)
    A[max_time[1]] -= 1
    k -= 1
    A.sort(reverse=True)

print(max(time)[0])

Submission status: Time Limit Exceeded

Solution code:
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]

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

l = -1
r = 10**18

while l+1<r:
    mid = (l+r)//2
    
    #mid を実現するトータルの回数がk回以内に収まるかどうか
    kaisuu = 0
    for i in range(n):
        if a[i]*f[i] > mid:
            kaisuu += (a[i] - int(mid/f[i]))
    if kaisuu > k:
        #実現不可能
        l = mid
    else:
        r =mid

print(r)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort(reverse=True)
f.sort()
a=np.array(a)
f=np.array(f)
for i in range(k):
    t=a*f.T
    t_mx=np.argmax(t)
    a[t_mx]=a[t_mx]-1
    a=np.sort(a)[::-1]
    if a[0]==0:
        break

t_mx=np.max(a*f.T)
print(t_mx)

Submission status: Time Limit Exceeded

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

for i in range(k):
    t=[a*f for (a,f) in zip(a,f)]
    t_mx=t.index(max(t))
    a[t_mx]=a[t_mx]-1
    a.sort(reverse=True)
    if a[0]==0:
        break

t=[a*f for (a,f) in zip(a,f)]
t.sort(reverse=True)
print(t[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())))[::-1]
def is_time(x):
  c = 0
  for i in range(n):
    c += max(0, A[i] - x//F[i])
  if c <= k:
    return True
  return False
ng = -1
ok = 0
for i in range(n):
  ok = max(ok, A[i]*F[i])
while ok - ng > 1:
  m = (ng + ok)//2
  if is_time(m):
    ok = m
  else:
    ng = m
print(ok)

Submission status: Time Limit Exceeded

Solution code:
import math
def yn(a, f, k, x):
  k_yt = 0
  for i in range(len(a)):
    ki = max(0, a[i]-math.floor(x/f[i]))
    k_yt += ki
  if k_yt <= k:
    return True
  else:
    return False

n, k = map(int, input().split())
a = list((map(int, input().split())))
f = list((map(int, input().split())))
a.sort()
f.sort(reverse = True)
xo = max([a[i]*f[i] for i in range(len(a))])
# binary search
if xo == 0:
  print(0)
else:
  l = 0
  r = xo
  m = xo
  while l <= r:
    piv = int((r+l)/2)
    if yn(a, f, k, piv):
      r = piv - 1 
      m = piv
    else:
      l = piv +1
  print(m)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappop, heappush

N, K = map(int, input().split())
digests = list(map(int, input().split()))
foods = list(map(int, input().split()))
foods.sort()
digests.sort(reverse=True)
hq = []
for i in range(N):
  heappush(hq, (-digests[i]*foods[i], digests[i], foods[i]))
for _ in range(K):
  cost, digest, food = heappop(hq)
  if cost == 0:
    heappush(hq, (0, 0, 0))
    break
  heappush(hq, (-(digest-1)*food, digest-1, food))
ans = 0
max_c, digest, food = heappop(hq)
print(-max_c)

Submission status: Time Limit Exceeded

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

tmp_m = [None, None]
while True:
    tmp_m[1] = 0
    if k == 0:
        break
    for i in range(n):
        if a[i]*f[i] > tmp_m[1]:
            tmp_m[0] = i
            tmp_m[1] = a[i]*f[i]
    if tmp_m[1] == 0:
        break
    a[tmp_m[0]] -= 1
    k -= 1

time_l = []

for i in range(n):
    time_l.append(a[i]*f[i])

print(max(time_l))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
AS = list(map(int, input().split()))
FS = list(map(int, input().split()))
AS.sort(); FS.sort(reverse=True)

def isValid(x):
    trains = 0
    for i in range(N):
        num = AS[i] * FS[i]
        while num > x:
            trains += 1
            num -= FS[i]
    return trains <= K

def binarySearch(lo, hi):
    if lo >= hi:
        return lo
    mid = lo + (hi - lo) // 2
    if isValid(mid):
        return binarySearch(lo, mid)
    else:
        return binarySearch(mid + 1, hi)
            
print(binarySearch(0, max(AS[i] * FS[i] for i in range(N))))

Submission status: Time Limit Exceeded

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

a.sort(reverse=True)
f.sort(reverse=False)

def isok(mid):
    total = 0
    for i in range(n):
        if a[i] * f[i] <= mid:
            continue
        total += a[i] - mid // f[i]
    return total <= k

ng = -1
ok = a[0] * f[-1] + 1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2

    if isok(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Time Limit Exceeded

Solution code:
def check(limit, max_training, costs, volumes):
    from math import floor
    remain_training = max_training
    for id, (cost, volume) in enumerate(zip(costs, volumes)):
        if cost * volume <= limit:
            continue
        else:
            lowest_cost = floor(limit / volume)
            remain_training -= (cost - lowest_cost)
        if remain_training < 0:
            return False
    return True


def main():
    n, k = map(int, input().rstrip("\n").split(" "))
    costs = list(map(int, input().rstrip("\n").split(" ")))
    volumes = list(map(int, input().rstrip("\n").split(" ")))

    costs.sort()
    volumes.sort(reverse=True)
    queue = []
    total_cost = 0

    success = False

    max_cost = max([cost * volume for cost, volume in zip(costs, volumes)])
    min_cost = 0

    while (min_cost + 1) < max_cost:
        center_cost = (min_cost + max_cost) // 2
        success = check(center_cost, k, costs, volumes)
        if success:
            max_cost = center_cost
        else:
            min_cost = center_cost
    if check(min_cost, k, costs, volumes):
        print(min_cost)
    else:
        print(max_cost)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# input 
def findmax(al, fl):
  max_n = -1
  max_id = -1
  for i in range(len(al)):
    if al[i]*fl[i] > max_n:
      max_n = al[i]*fl[i]
      max_id = i
  return max_n, max_id
n, k = map(int, input().split())
al = list(map(int, input().split()))
fl = list(map(int, input().split()))
al.sort()
fl.sort(reverse=True)
ans = max([al[i]*fl[i] for i in range(n)])
while k > 0 and sum(al) > 0:
    max_n, idx = findmax(al, fl)
    al[idx] -= 1
    k -= 1
ans = max([al[i]*fl[i] for i in range(n)])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# # 整数の入力
# a = int(input())
# # スペース区切りの整数の入力
# b, c = map(int, input().split())
# # 文字列の入力
# s = input()
# a = []
# a = list(map(int, input().split()))
# import math

# 解説参照済み

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

a.sort()
f.sort(reverse=True)
ans = 0

maxaf = 0
for i in range(n):
    maxaf = max(maxaf, a[i] * f[i])

left = 0
right = maxaf

while left < right:
    # print(left, right)
    mid = (left + right) // 2
    ktemp = k
    renewleft = False
    for i in range(n):
        if a[i] * f[i] > mid:
            if (a[i] * f[i] - mid + f[i] - 1) // f[i] > ktemp:
                left = mid + 1
                renewleft = True
                break
            else:
                ktemp -= (a[i] * f[i] - mid + f[i] - 1) // f[i]
    if not renewleft:
        right = mid

print(left)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = map(int, input().rstrip("\n").split(" "))
    costs = list(map(int, input().rstrip("\n").split(" ")))
    volumes = list(map(int, input().rstrip("\n").split(" ")))
    
    costs.sort()
    volumes.sort(reverse=True)
    from heapq import heappush, heappop
    queue = []
    total_cost = 0
    for id, (cost, volume) in enumerate(zip(costs, volumes)):
        total_cost += cost
        heappush(queue, (cost * volume * -1,id, cost, volume))
    for i in range(min(total_cost, k)):
        
        duration, id, cost, volume = heappop(queue)
        cost -= 1
        if cost > 0:
            heappush(queue, (cost * volume * -1, id, cost, volume) )
        
        if not queue:
            break
    if queue:
        result = min([duration for duration, id, cost, volume in queue])
        print(result * -1)
    else:
        print(0)
    

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import math

A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort()

N=A[0]
K=A[1]

smax=0
for i in range(N):
    if smax<=B[i]*C[i]:
        smax=B[i]*C[i]

flag=True
a=smax
b=0
n=int(smax/2)

K1=0

while flag:
  if a-b==1:
     flag=False
  else:
      ssum=0
      for i in range(N):
          if (B[i]*C[i])>n:
              ssum=ssum+math.ceil((B[i]*C[i]-n)/C[i])
      if ssum>K:
          b=n
          n=(a+n)//2
      else:
          a=n
          n=(n+b)//2

if sum(B)<=K:
 print(0)
else:
 print(a)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
cost = sorted(list(map(int,input().split())), reverse=True)
t = sorted(list(map(int,input().split())))
t_list = [cost[i]*t[i] for i in range(n)]
t_max = max(t_list)
for j in range(k):
    for i in range(n):
        if cost[i] * t[i] == t_max:
            cost[i]-=1
            t_list[i] = cost[i] * t[i]
            t_max = max(t_list)
            break

if max(t_list) < 0:
    print(0)
else:
    print(max(t_list))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()), reverse=True)

ans = []
for x, y in zip(a, f):
    ans.append(x * y)
for z in range(k):
    ans[int(ans.index(max(ans)))] -= f[int(ans.index(max(ans)))]
if (max(ans) < 0):
    print(0)
    exit()
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    X = input().split(' ')
    A = input().split(' ')
    F = input().split(' ')
    
    n = int(X[0])
    k = int(X[1])
    
    A = np.array([int(s) for s in A])
    F = np.array([int(s) for s in F])

    A.sort() 
    F = np.sort(F)[::-1]

    T = A*F
    max_index = np.argmax(T)

    for i in range(k):
        T[max_index] -= F[max_index]
        max_index = np.argmax(T)
    
    if np.max(T) < 0:
        print('0')
        return
    print(np.max(T))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

#output
import numpy as np
A = np.array(A)
F = np.array(F)

A = np.sort(A)[::-1]
F = np.sort(F)
B = np.sum(A)
M = max([a*f for a, f in zip(A, F)])

def is_possible(x):
    return B - np.minimum(A, x//F).sum() <= K

for i in range(M):
    if is_possible(i):
        print(i)
        break

Submission status: Time Limit Exceeded

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

low = -1
up = 10 ** 12

while low+1<up:
    middle = (low + up) // 2

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

        if(red > K):
            break
    
    if(red <= K):
        up = middle
    else:
        low = middle

print(up)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

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

def biserch(ok,ng,judge):
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if judge(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = biserch(10**12, -1, judge)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = sorted(list(map(int, args[1].split())))
    F = sorted(list(map(int, args[2].split())), reverse=True)

    for _ in range(k):
        if A[-1] == 0:
            break

        max_af = 0
        max_i = -1

        for i in range(n):
            af = A[i]*F[i]
            if max_af < af:
                max_i = i
                max_af = af

        A[max_i] -= 1
        A.sort()

    ret = 0
    for i in range(n):
        ret = max(ret, A[i]*F[i])

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().split('\n'))))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = map(int,input().split())
A_list =  list(map(int, input().split()))
F_list =  list(map(int, input().split()))

eat_time = []
A_list.sort() #min max
F_list.sort(reverse=True) #max -min
A_array = np.array(A_list)
F_array = np.array(F_list)
eat_time =A_array*F_array

for l in range(0,K,1):
    max_num=0
    max_index=np.where(eat_time == eat_time.max())
          
    if len(max_index[0])==1:
        A_array[max_index] -=1
        A_array.sort()
        eat_time =A_array*F_array
    else:
        for x in max_index[0]:
            if max_num < F_array[x]:
                max_num =x
        A_array[max_num] -=1
        A_array.sort()
        eat_time =A_array*F_array

    if eat_time.max() ==0:
        break
sum_Num = np.sum(eat_time)
print(eat_time.max())

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
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))
x=np.array(list(map(mul,a,f)))
b=sum(a)
c=min(b,k)
for i in range(c):
  z=x.argmax()
  a[z]-=1
  x[z]-=f[z]
  
print(max(x))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
l_a = list(map(int,input().split()))
l_f = list(map(int,input().split()))
l_a.sort()
l_f.sort(reverse = True )
ll = [l_a[a]*l_f[a] for a in range(N)]
x = max(ll)
m = 0
while m == 0:
    lim = 0
    for a in range(N):
        lim += max(0,l_a[a]-x//l_f[a])
    if lim <= K:
        x -= 1
    else:
        m = 1
print(x+1)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
x=list(map(mul,a,f))
b=sum(a)
c=min(b,k)
for i in range(c):
  y=max(x)
  z=x.index(y)
  a[z]-=1
  x[z]-=f[z]
  
print(max(x))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = sorted(list(map(int, input().split())))

ans = 10 ** 12
count = 0
for j in range(K+1):

    A.sort(reverse=True)
    muls = [x * y for(x,y) in zip(A, F)]

    tmp = max(muls)

    if(ans > tmp):
        ans = tmp
        count = 0
    else:
        count += 1

    if(ans == 0 or j == K or count == N):
        break

    idx = muls.index(tmp)
    A[idx] -= 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = sorted(list(map(int, input().split())))

ans = 10 ** 12
for j in range(K+1):

    A.sort(reverse=True)
    muls = [x * y for(x,y) in zip(A, F)]

    tmp = max(muls)
    ans = tmp

    if(ans == 0 or j == K):
        break

    idx = muls.index(tmp)
    A[idx] -= 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = sorted(list(map(int, input().split())))

ans = 10 ** 12
for j in range(K+1):

    A.sort(reverse=True)
    multiples = [A[i] * F[i] for i in range(N)]

    tmp = max(multiples)
    ans = tmp

    if(ans == 0 or j == K):
        break

    idx = multiples.index(tmp)
    A[idx] -= 1
    
print(ans)

Submission status: Time Limit Exceeded

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

sumA = sum(A)
if  K >= sumA:
    print(0)
    exit()

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

ng = -1
ok = 10**12+1

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

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())

a=list(map(int,input().split()))
f=list(map(int,input().split()))
cnt=[]
a.sort()
f.sort(reverse=True)
for i in range(n):
    cv=a[i]*f[i]
    cnt.append(cv)

def judge(s):
    tmp=k
    for i in range(n):
        if cnt[i]>s:
            if (cnt[i]-s)%f[i]==0:
                vv=(cnt[i]-s)//f[i]
            else:
                vv=1+(cnt[i]-s)//f[i]
            tmp-=vv
    if tmp<0:
        return False
    return True

left=-1
right=10**18

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

print(right)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
x=list(map(mul,a,f))
b=sum(a)
c=min(b,k)
for i in range(c):
  y=max(x)
  z=x.index(y)
  a[z]-=1
  x[z]-=f[z]

x=list(map(mul, a, f))
print(max(x))

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
x=list(map(mul,a,f))
for i in range(k):
  y=max(x)
  z=x.index(y)
  a[z]-=1
  x[z]-=f[z]

x=list(map(mul, a, f))
print(max(max(x),0))

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
import math
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
x=list(map(mul,a,f))
for i in range(k):
  y=max(x)
  z=x.index(y)
  a[z]-=1
  x[z]-=f[z]

a.sort()
x=list(map(mul, a, f))
print(max(max(x),0))

Submission status: Time Limit Exceeded

Solution 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 = -1
R = 10**12 +1 
while R-L>1:
    Mid = (L+R)//2
    tmp = 0
    for a,f in zip(A,F):
        tmp += max(0, a-Mid//f)
    if tmp<=K:
        R = Mid
    else:
        L = Mid
print(R)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
f.sort()
f.reverse()
for i in range(k):
  a.sort()
  x=list(map(mul, a, f))
  y=max(x)
  a[x.index(y)]-=1

a.sort()
x=list(map(mul, a, f))
print(max(x))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a_list=sorted(list(map(int,input().split())))#昇順
f_list=sorted(list(map(int,input().split())),reverse=True)#降順
while k>0 or not any(a_list):
    M=-1
    k-=1
    for i,(a,f) in enumerate(zip(a_list,f_list)):
        if M<a*f:
            M=a*f
            train_num=i
    a_list[train_num]-=1
M=-1    
for i,(a,f) in enumerate(zip(a_list,f_list)):
        if M<a*f:
            M=a*f

print(M)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
import math
import numpy as np
n,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
f=np.array(list(map(int,input().split())))
f=np.sort(f)[::-1]
for i in range(k):
  a.sort()
  x=list(map(mul, a, f))
  y=max(x)
  a[x.index(y)]-=1

a.sort()
x=list(map(mul, a, f))
print(max(x))

Submission status: Time Limit Exceeded

Solution code:
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse = True)
time = []
time2 = []
for i in range(n):
  t = a[i]*f[i]
  l = [t, f[i]]
  time.append(l)
  time2.append(t)
maxtime = max(time2)
time.sort(reverse=True)
up = maxtime
tem = maxtime//2
low = 0
if sum(a) <= k:
  print(0)
else:
  while True:
    l = k
    for i in range(n):
      if time[i][0] > tem:
        l -= math.ceil((time[i][0]-tem)/time[i][1])
    if l >= 0:
      form = tem
      up = tem
      tem = math.floor((tem+low)/2)
    else:
      form = tem
      low = tem
      tem = math.ceil((tem+up)/2)
    if up- low <= 1:
      break
  print(up)

Submission status: Time Limit Exceeded

Solution code:
# input
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

# 考え方
# 目標：最大値の最小化
# にぶたん
# 必要条件：A[i] <= A[i+1] => F[i] >= F[i+1]

# sort
# Aは昇順、Fは降順(任意)
A = sorted(A)
F = sorted(F, reverse=True)

# にぶたん(参考：juppy)
ng = -1
ok = 10 ** 12  # 取り得る最大値

while ok - ng > 1:  # 収束判定
    mid = (ok + ng) // 2
    cost = 0

    for i, e in enumerate(A):
        cost += max(0, e - mid // F[i])
    
    if cost <= K:
        ok = mid
    
    else:
        ng = mid

print(ok)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int,input().split())
a = np.array(sorted([i for i in map(int,input().split())]))
f = np.array(sorted([i for i in map(int,input().split())],reverse=True))

r = a * f

for i in range(0,k):
	r[np.argmax(r)] -= f[np.argmax(r)]

print(max(r))