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: Runtime Error

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(reverse=True)
def flag(x):
    cou = 0
    for i in range(N):
        cou += max(A[i] - x//F[i], 0)
    return bool(K >= cou)

low = 0
high = 10**12

while low <= high:
    mid = (low + high) // 2
    if flag(mid):
        if not flag(mid-1):
            ans = mid
            break
        else:
            high = mid - 1
    else:
        low = mid + 1

print(ans)

Submission status: Runtime Error

Solution code:
# 15:45-16:20
# pdf had been seen


import math

def main():
  n, k = map(int, input().split()) 
  a = sorted(list(map(int, input().split())))
  f = sorted(list(map(int, input().split())), reverse=True)

  lo = 0
  hi = sum(ai * fi for ai, fi in zip(a, f))
  mid = (hi + lo) // 2
  ans = hi

  for i in range(hi):
    cost = sum(max(0, ai - math.floor(mid / fi)) for ai, fi in zip(a,f))
    if k >= cost:
      hi = mid
      ans = mid
    else:
      lo = mid + 1
    if hi == lo:
      break;
    mid = (hi + lo) // 2
  
  print(ans)


if __ name__ == "__main__":
  main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,K = MI()
	A = LI();A.sort();A=np.array(A)
	F = LI();F.sort(reverse=True);F=np.array(F)

	def BinarySearch(upper_X, lower_X):
		X = upper_X//2 
		while upper_X > lower_X:
			P = A-X//F
			if(K < sum((P[P>=0]))):
				lower_X = X
				if(upper_X - lower_X) <= 1: break
			else:
				candidate = X
				upper_X = X
			X = (lower_X+upper_X)//2
		return candidate

	print(BinarySearch(max(A*F),0))


main()

Submission status: Runtime Error

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

def ok(N):
    sums=0
    for i in range(n):
        sums+=max(0,a[i]-N//b[i])
    if sums<=k:
        return True
    else:
        return False
    
import math

left=0
right=a[0]*b[-1]
for _ in range(math.ceil(math.log2(right))):
    if ok(math.floor((left+right)/2)):
      left=left
      right=(left+right)/2
    elif not ok(math.floor((left+right)/2)):
      left=(left+right)/2
      right=right
print(math.floor(right))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=sorted(a,reverse=True)
b=sorted(b)

def ok(N):
    sums=0
    for i in range(n):
        sums+=max(0,a[i]-N//b[i])
    if sums<=k:
        return True
    else:
        return False
    
import math

left=0
right=a[0]*b[-1]
for _ in range(math.ceil(math.log2(right))):
    if ok(math.floor((left+right)/2)):
      left=left
      right=(left+right)/2
    elif not ok(math.floor((left+right)/2)):
      left=(left+right)/2
      right=right
print(math.floor(right))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=sorted(a,reverse=True)
b=sorted(b)

def ok(N):
    sums=0
    for i in range(n):
        sums+=max(0,a[i]-N//b[i])
    if sums<=k:
        return True
    else:
        return False
    
import math

left=0
right=a[-1]*b[0]+1
for _ in range(math.ceil(math.log2(right))+1):
    if ok(math.floor((left+right)/2)):
      left=left
      right=(left+right)/2
    elif not ok(math.floor((left+right)/2)):
      left=(left+right)/2
      right=right
print(math.floor(right))

Submission status: Runtime Error

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

a = np.array(input().split(),np.int)

F = np.array(input().split(),np.int)

A.sort()
F.sort()

F_ = F[::-1]

left = -1
right = (A * F_).sum()

while (right - left) > 1:
    s = (left + right) // 2
    q = np.maximum(0, A - s // F_)
    r = (q.sum() <= k)
    if r:
        right = s 
    else:
        left = s 

print(right)

Submission status: Runtime Error

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

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

left = -1
right = (A * F).sum()

while (right - left) > 1:
    s = (left + right) // 2
    r = np.maximum(0, A - s // F).sum() <= k
    if r:
        right = s 
    else:
        left = s 

print(right)

Submission status: Runtime Error

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

a = np.array(input().split(),np.int)

F = np.array(input().split(),np.int)

A.sort()
F.sort()

F = F[::-1]

left = -1
right = (A * F).sum()

while (right - left) > 1:
    s = (left + right) // 2
    r = np.maximum(0, A - s // F).sum() <= k
    if r:
        right = s 
    else:
        left = s 

print(right)

Submission status: Runtime Error

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

a = np.array(input().split(),np.int)

F = np.array(input().split(),np.int)

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

left = -1
right = (A * F).sum()

while (right - left) > 1:
    s = left + ((right - left) // 2)
    for i in range(n):
        b = np.minimum(s//F,A)
    if (A - b).sum() <= k:
        right = s 
    else:
        left = s 

print(right)

Submission status: Runtime Error

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

a = np.array(input().split(),np.int)

F = np.array(input().split(),np.int)


A.sort()
F.sort()

F = F[::-1]

left = -1
right = (A * F).sum()

while (right - left) > 1:
    b = np.zeros(n,dtype = int)
    s = left + ((right - left) // 2)
    for i in range(n):
        b = np.minimum(s//F,A)
    if (A - b).sum() <= k:
        right = s 
    else:
        left = s 

print(right)

Submission status: Runtime Error

Solution code:
ng = -1
# 完食時間の最大はA=10**6, F=10**6の時。
ok = 10**12+1

def isok(x):
    # 最大の完食時間がxになるように修行する
    # その場合の修行回数の合計を求める
    # そしてそれがK回以下ならTrueを返す
    cnt = 0
    for a, f in zip(a_list,f_list):
        aprime = x // f
        cnt += max(a - aprime,0)
        
        if cnt > K:
            return False
    return True

while abs(ok-ng)>1:
    x = (ok+ng) // 2
    
    if isok(x):
        # train_cntが限界より多い場合、目指す最大の完食時間が短すぎる
        # よって完食時間を増やすべき
        # Kに等しい場合ももしかしたらもっといい
        ok = x
    else:
        ng = x
        
    print(ok,ng, train_cnt)

        
print(ok)

Submission status: Runtime Error

Solution code:
# 11 14
# 3 1 4 1 5 9 2 6 5 3 5 
# 8 9 7 9 3 2 3 8 4 6 2

N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
F = list(map(int, input().split())) # 食べにくさ

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

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K

my_range = range(0, 10**6)

def node(lst):
    if len(lst) % 2 == 0:
        mid_idx = int(len(lst)/2)
    else:
        mid_idx = int(math.floor(len(lst)/2))

    if len(lst) == 1:
        print(lst[mid_idx])
        return()

    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)

node(my_range)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
B = list(map(int, input().split())) # 食べにくさ

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

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K

my_range = range(0, 10**6)

def node(lst):
    if len(lst) % 2 == 0:
        mid_idx = int(len(lst)/2)
    else:
        mid_idx = int(math.floor(len(lst)/2))

    if len(lst) == 1:
        print(lst[mid_idx])
        return()

    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)

node(my_range)

Submission status: Runtime Error

Solution code:
# 11 14
# 3 1 4 1 5 9 2 6 5 3 5 
# 8 9 7 9 3 2 3 8 4 6 2

N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
B = list(map(int, input().split())) # 食べにくさ

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

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K

my_range = range(0, 10**6)

def node(lst):
    if len(lst) % 2 == 0:
        mid_idx = int(len(lst)/2)
    else:
        mid_idx = int(math.floor(len(lst)/2))

    if len(lst) == 1:
        print(lst[mid_idx])
        return

    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)

node(my_range)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
B = list(map(int, input().split())) # 食べにくさ

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

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K

my_range = range(0, 10**6)

def node(lst):
    if len(lst) % 2 == 0:
        mid_idx = int(len(lst)/2)
    else:
        mid_idx = int(math.floor(len(lst)/2))

    #print('mid_idx: ', mid_idx, lst[mid_idx], len(lst), min(lst), max(lst))

    if len(lst) == 1:
        print(lst[mid_idx])
        return

    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)

Submission status: Runtime Error

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

##　Aは昇順Fは降順に並び替える
A.sort() 
F.sort(reverse = True)

##　成績(A × F)の目標をxにしたときに何回修行が必要かを求める関数
def target(x):
    train_count = 0
    for i in range(N):
        a = A[i]
        targ_a = x // F[i] #目標を達成した時の消費コストA
        if targ_a < a:
            train_count = train_count + a - targ_a 
    return train_count <= K　#ただし合計がKを超えないもの

##　二分探索(リストを半分ずつ削って達成可能な目標を探す)
left = -1                        #一番左
right = A[-1] * F[0]             #一番右(Aの最大値 × Fの最大値)
while right > left + 1:          #一番右が一番左より大きい間（一致したら終了）
    middle = (left + right) // 2 #真ん中
    if target(middle):           #目標を真ん中にして達成可能なら
        right = middle           #一番右を真ん中にする（残りの右側は無駄に時間かかってるから切り捨てる）
    
    else:                        #達成できないなら(K回を超えてしまうとき）
        left = middle            #一番左を真ん中にする（残りの左側は達成不可だから切り捨てる）

print(right)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

#Aを降順Fを昇順に並べる

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

#二つの要素同士をかける

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

#作業をK回繰り返す

for i in range(1, K):

#まずかけたやつのリストで最大のものが何番目なのかを取り出す

	n_max = combined1.index(max(combined1))

#それはli_aのインデックスと同じなのでそのインデックスのli_aの要素を取り出す
#その値から１引いて元に戻す

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

Submission status: Runtime Error

Solution code:
import math 

def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right

def costsum(x,y):
    siguma =0
    Asort = quick_sort(x)
    Fsort = quick_sort(y)
    for i in range(N):
        siguma = siguma + Asort[i]*Fsort[N-i-1]
    return siguma
def maxseki(x,y):
    seki = 0
    count = 0
    Asort = quick_sort(x)
    Fsort = quick_sort(y)
    for i in range(N):
        if seki < Asort[i]*Fsort[N-i-1]:
            seki = Asort[i]*Fsort[N-i-1]
            count = i
    return count

input1 = input()
input2 = input()
input3 = input()

hairetu1 = input1.split()
hairetu2 = input2.split()
hairetu3 = input3.split()
N = int(hairetu1[0])
K = int(hairetu1[1])
A = [int(s) for s in hairetu2] 
F = [int(t) for t in hairetu3]

Asort = quick_sort(A)
Fsort = quick_sort(F)

for i in range(K):
    s=maxseki(Asort,Fsort)
    Asort[s]=Asort[s]-1


P = maxseki(Asort,Fsort)
maxcost = Asort[P]*Fsort[N-P-1]
if maxcost < 0:
    maxcost = 0
print (maxcost)

Submission status: Runtime Error

Solution code:
import math 

def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right

def costsum(x,y):
    siguma =0
    Asort = quick_sort(x)
    Fsort = quick_sort(y)
    for i in range(N):
        siguma = siguma + Asort[i]*Fsort[N-i-1]
    return siguma
def maxseki(x,y):
    seki = 0
    count = 0
    Asort = quick_sort(x)
    Fsort = quick_sort(y)
    for i in range(N):
        if seki < Asort[i]*Fsort[N-i-1]:
            seki = Asort[i]*Fsort[N-i-1]
            count = i
    return count

input1 = input()
input2 = input()
input3 = input()

hairetu1 = input1.split()
hairetu2 = input2.split()
hairetu3 = input3.split()
N = int(hairetu1[0])
K = int(hairetu1[1])
A = [int(s) for s in hairetu2] 
F = [int(t) for t in hairetu3]

Asort = quick_sort(A)
Fsort = quick_sort(F)

for i in range(K):
    s=maxseki(Asort,Fsort)
    Asort[s]=Asort[s]-1


P = maxseki(Asort,Fsort)
maxcost = Asort[P]*Fsort[N-P-1]
print (maxcost)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sott(reverse = True)
T = [A[i]*B[i] for i in range(0,N)]
# 二分法
ma = A[N]*F[0]
mi = 0
line = 0
flag = 1

while flag:
    count = 0
    for i in range(0,N):
        if T[i] > line:
            count += A[i]-line//F[i]
    if ma-mi < 1:
        print(int(line))
        flag = 0
    else:
        if count > K:
            mi = line
        else:
            M = line
    line = (ma+mi)/2

Submission status: Runtime Error

Solution code:
#E
N,K = map(int,input().split())
A = list(map(int,input.split()))
F = list(map(int,input.split()))
A.sort()
F.sott(reverse = True)
T = [A[i]*B[i] for i in range(0,N)]
# 二分法
ma = A[N]*F[0]
mi = 0
line = 0
flag = 1

while flag:
    count = 0
    for i in range(0,N):
        count += int((F[i]-line+1)/F[i])
    if ma-mi < 1:
        print(int(line))
        flag = 0
    else:
        if count > K:
            mi = line
        else:
            M = line
    line = (ma+mi)/2

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10000)
def culc(s,x,m,F_array,eat_time):
    if x == 0:
        return 0
    K_sum = eat_time/F_array
    must_del = K_sum[K_sum > K]
    must_del = must_del - x
    sum_del = int(np.sum(must_del))
    print(x)
    print(sum_del)
    if sum_del == x:
        return x

    if sum_del > x:
        s = x
        x = int((x+m)/2)
        return culc(s,x,m,F_array,eat_time)
    else:
        m = x
        x = int((x+s)/2)
        return culc(s,x,m,F_array,eat_time)


N,K = map(int,input().split())
A_list =  list(map(int, input().split()))
F_list =  list(map(int, input().split()))
s = 0
m = 1.0e+18
x = 5.0e+17
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

print(culc(s,x,m,F_array,eat_time))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10000)
def culc(s,x,m,F_array,eat_time):
   
    K_sum = eat_time/F_array
    must_del = K_sum[K_sum > x]
    must_del = must_del - x
    sum_del = int(np.sum(must_del))
    print(x)
    print(sum_del)
    if sum_del == x:
        return x

    if sum_del > x:
        s = x
        x = int((x+m)/2)
        return culc(s,x,m,F_array,eat_time)
    else:
        m = x
        x = int((x+s)/2)
        return culc(s,x,m,F_array,eat_time)


N,K = map(int,input().split())
A_list =  list(map(int, input().split()))
F_list =  list(map(int, input().split()))
s = 0
m = 1.0e+18
x = 5.0e+17
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

print(culc(s,x,m,F_array,eat_time))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10000)
def culc(s,x,m,F_array,eat_time):
   
    K_sum = eat_time/F_array
    must_del = K_sum[K_sum > x]
    must_del = must_del - x
    sum_del = int(np.sum(must_del))
    print(x)
    print(sum_del)
    if sum_del == x:
        return x

    if sum_del > x:
        s = x
        x = int((x+m)/2)
        return culc(s,x,m,F_array,eat_time)
    else:
        m = x
        x = int((x+s)/2)
        return culc(s,x,m,F_array,eat_time)


import numpy as np
N,K = map(int,input().split())
A_list =  list(map(int, input().split()))
F_list =  list(map(int, input().split()))
s = 0
m = 1.0e+18
x = 5.0e+17
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

print(culc(s,x,m,F_array,eat_time))

Submission status: Runtime Error

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())) 
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: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

ll N, K;
int A[212345], F[212345];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", A + i);
	REP(i, N) scanf("%d", F + i);
	
	sort(A, A + N);
	sort(F, F + N, greater<int>());
	
	ll l = -1, r = longINF;
	
	while (r - l > 1) {
		ll m = (l + r) / 2;
		ll sum = 0;
		REP(i, N) sum += max<ll>(0, A[i] - m / F[i]);
		if (sum <= K) r = m;
		else l = m;
	}
	
	cout << r << endl;
	
	return 0;
}

Submission status: Runtime Error

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, reverese=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: Runtime Error

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 = 0
    r = max(a * f for a, f in zip(A, F))
     
    while l < r:
        m = (l + r) // 2
        if sum(max(a - m // f, 0) for a, f in zip(A, F)) <= K:
            r = m
        else:
            l = m + 1
     
    print(r)

Submission status: Runtime Error

Solution code:
import numpy as np

listNK = np.array(map(int, input().split()))
A_i = np.array(map(int, input().split()))
F_i = np.array(map(int, input().split()))
N = listNK[0]
K = listNK[1]
np.sort(A_i)
np.sort(F_i, reverse=True)
score = [0] * N
while K > 0 and A_i[N-1] > 0:
    MaxScore = 0
    for i in range(N):
        score[i] = A_i[i] * F_i[i]
        if score[i] > MaxScore:
            index = i
            MaxScore = score[i]
    A_i[index] = A_i[index] - 1
    K = K - 1
    np.sort(A_i)
MaxScore = 0
for i in range(N):
    score[i] = A_i[i] * F_i[i]
    if score[i] > MaxScore:
        index = i
        MaxScore = score[i]
print(MaxScore)

Submission status: Runtime Error

Solution code:
import numpy as np

def solve(n, k, aaa, fff):
  aaa = np.sort(aaa)
  fff = np.sort(fff)[::-1]
  
  l = 0
  r = 10**12
  while l<=r:
    m = (l+r)//2
    req = np.clip(aaa - m//fff, 0, None).sum()

    if req < k:
      r = m-1
    else:
      l = m+1

  return l


N, K = map(int,input().split())
aaa = np.array(list(map(int,input().split())))
fff = np.array(list(map(int,input().split())))

print(solve(N, K, aaa, fff)

Submission status: Runtime Error

Solution code:
import numpy as np

def solve(n, k, aaa, fff):
  aaa = np.sort(aaa)
  fff = np.sort(fff)[::-1]
  
  l = 0
  r = 10**12
  while l<=r:
    m = (l+r)//2
    req = np.clip(aaa - m//fff, 0, Nonw).sum()

    if req < k:
      r = m-1
    else:
      l = m+1

  return l


N, K = map(int,input().split())
aaa = np.array(list(map(int,input().split())))
fff = np.array(list(map(int,input().split())))

print(solve(N, K, aaa, fff)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long long int n,k;
    long long int a[200010],f[200010];
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i<n; i++) cin >> f[i];
    sort(a,a+n);
    sort(f, f + n, greater<int>());
    long long int left=0;
    long long int right=1000000000000;
    while(left<=right){
    long long int m=(left+right)/2;
    long long int c=0;
    for(int i=0;i<n;i++){
        c+=a[i]-m/f[i];
    }
    if(c<=k) right=m;
      else left=m+1;
    }
    cout << right << endl;
}

Submission status: Runtime Error

Solution code:
import numpy as np

a,b=map(int,input().split())
A=np.array(sorted(list(map(int,input().split()))))
F=np.array(sorted(list(map(int,input().split())),reverse=True))

s=A.sum()

x=-1
y=10**12
while x+1<y:
  mid=(x+y)//2
  if s-np.minimum(A,mid//F).sum()<=K:
    x=mid
  else:
    y=mid
print(mid)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse = True)
 
P = [A[i]*F[i] for i in range(n)]
 
def b(p):
    result = 0
    for i in range(n):
        result += A[i] - p / F[i]
    return result
 
if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) / 2
    bm = b(middle)
    while right - left > 1:
        
        if bm > k: left = middle
        else: right = middle
        
        middle = (left + right) / 2
        bm = b(middle)
    
    if b(int(left)) == k: print(int(left))
    elif: b(int(right)) <= k: print(int(right))
    else: print(int(right) + 1)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
list_A=list(map(int,input().split()))
list_F=list(map()int,input().split())
list_A_sort=list_A.sort()
list_F_sort=list_F.sort()
list_F_reverse=list_F_sort.reverse()

list_A1=[]
for x in list_A_sort:
  list_A1.append(x-1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse = True)
P = [A[i]*F[i] for i in range(n)]
min_list = sorted(list(set(P)))
if sum(A) <= k: print('0')
else:
    new_P = [0 for i in range(n)]
    i=0
    while k > sum(new_P):
        print(new_P)
        new_min = min_list[i]
        i += 1
        for j in range(n):
            if (P[j] - new_min) > 0: new_P[j] = (P[i] - new_min) // F[j] + 1
    print(new_min)

Submission status: Runtime Error

Solution code:
(_,K),*T=[map(int,t.split())for t in open(0)]
A,B=map(sorted,t)
m,M,i=0,2**40,1
exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K else((i+M)//2,M,i);"*41)
print(M)

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
BCs = [b,a*b for a,b in zip(sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1])]

def f(target):
    return sum([math.ceil(max(0, c - target)/b)for b, c in BCs])<=K

if __name__ == '__main__':
    min_i, max_i, index = 0, 10**12, 1
    while True:
        if f(index):
            index, max_i = (index-1 + min_i)//2, index-1
        else:
            index, min_i = (index+1 + max_i)//2, index+1
        if min_i > max_i:
            print(min_i)
            break