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: Wrong Answer

Solution code:

def main():
    n,k=map(int,input().split(' '))
    a=sorted(list(map(int,input().split(' '))),reverse=True)
    f=sorted(list(map(int,input().split(' '))))
    lb=0
    ub = 0
    for i,j in zip(a,f):
        ub = max(ub,i*j)
    def C(x):
        k_tmp = k
        for i,j in zip(a,f):
            k_tmp -= i-x//j
            if k_tmp < 0:
                return False
        return True

    while ub!=lb:
        mid = (lb+ub)//2
        if C(mid):
            ub = mid
        else:
            lb = mid+1
    print(ub)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n,k=map(int,input().split(' '))
    a=sorted(list(map(int,input().split(' '))),reverse=True)
    f=sorted(list(map(int,input().split(' '))))
    lb=0
    ub = 0
    for i,j in zip(a,f):
        ub = max(ub,i*j)
    def C(x):
        k_tmp = k
        for i,j in zip(a,f):
            k_tmp -= i-x//j
            if k_tmp < 0:
                return False
        return True

    while ub-lb>1:
        mid = (lb+ub)/2
        if C(mid):
            ub = mid
        else:
            lb = mid
    if C(lb):
        print(int(lb))
    else:
        print(int(ub))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)

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

def solve(x):
	total=0
	for i in range(n):
		total+=a[i]-max(0,x//f[i])
	return total<=k

#xの範囲 ngは実現が難しい方
ok=maxaf
ng=-1

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

Submission status: Wrong Answer

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)

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

def solve(x):
	total=0
	for i in range(n):
		total+=a[i]-x//f[i]
	return total<=k

#xの範囲 ngは実現が難しい方
ok=maxaf
ng=-1

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

Submission status: Wrong Answer

Solution code:
from numpy import array, int64, minimum
from sys import stdin

def main():
    input = stdin.buffer.readline

    N, K = map(int, input().split())

    A, F = array(input().split(), int64), array(sorted(input().split(), reverse=True), int64)
    A.sort()

    sum_A = A.sum()

    ng, ok = -1, 10 ** 12
    while ng + 1 < ok:
        mid = (ok + ng) // 2
        if (sum_A - minimum(A, mid // F).sum()) <= K:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)

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

def solve(x):
	total=0
	for i in range(n):
		total+=a[i]-x//f[i]
	return total<=k

#xの範囲 ngは実現が難しい方
ok=maxaf
ng=0

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# Aを昇順、Fを降順に並べ替える
# 消化コストの小さい人に食べにくい食べ物を食べてもらう
A.sort()
F.sort()
F=F[::-1]
sumA = A.sum()

def can_eat(x):
  # 全員がx秒以下で食べられるか調べる
  
  # 食べにくさfの食べ物をx秒以内に食べるための消化コストa'は、
  # a' * f <= x  ->  a' <= x / f
  # a'は整数とすると
  # a' = x // f
  
  # 各消化コストaのうち、a'(x秒以下に収めるための消化コスト)を
  # 超えているものについては、a'に収める
  # こうして、x秒以下に収まっている消化コストの配列を作る
  eat_cost_for_x = np.minimum(A, x // F)
  
  # 元の消化コストの合計と、
  # x秒以下に収まっている消化コスト（eat_cost_for_x）の合計を比較し、
  # 修行できる回数(K)以内の差であれば、全員x秒以下で食べられる
  return sumA - eat_cost_for_x.sum() <= K


# 不可能目標（最小でも0秒のため）
left = -1 
# 可能目標 (a <= 10^6, f <= 10^6 なので、a*f <= 10^12)
right = 10**12

# 二分探索でtest(x)がtrueとなるxの最小値を探索する
# left = rightとなるまで繰り返す
while left < right:
  mid = (left+right)//2
  
  # mid秒で食べられる場合は探索範囲の右端をmidにする
  if can_eat(mid):
    right = mid
  # mid秒で食べられない場合は探索範囲の左端をmid+1にする
  else:
    left = mid + 1
 
answer = left
print(answer)

Submission status: Wrong Answer

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=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    h+=a[i]-(f[i]//mid)
  if h<=k:ok=mid
  else:ng=mid
print(ok)

Submission status: Wrong Answer

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)

def solve(x):
	total=0
	for i in range(n):
		total+=a[i]-x//f[i]
	return total<=k

#xの範囲 ngは実現が難しい方
ok=a[-1]*f[0]
ng=0

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

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().strip().split(' '))
A = sorted(list(map(int, input().strip().split(' '))), reverse=True)
F = sorted(list(map(int, input().strip().split(' '))))
if sum(A) <= K:
  print(0)
  exit()

ng = 0
ok = max([a*f for a,f in zip(A,F)])
while True:
  if ok-ng < 2: break
  k = int((ng+ok)/2)
  now_cost = 0
  for a,f in zip(A,F):
    now_cost += a-(k//f)
  if now_cost > K:
    ng = k
  else:
    ok = k
    
print(ok)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().strip().split(' '))
A = sorted(list(map(int, input().strip().split(' '))), reverse=True)
F = sorted(list(map(int, input().strip().split(' '))))
if sum(A) <= K:
  print(0)
  exit()

ng = 0
ok = 1000000000000
while True:
  if ok-ng == 1: break
  m = int((ng+ok)/2)
  now_cost = 0
  for a,f in zip(A,F):
    now_cost += a-(m//f)
  if now_cost > K:
    ng = m
  else:
    ok = m
    
print(ok)

Submission status: Wrong Answer

Solution code:
import math

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) # A[i]を降順ソート
F.sort() # F[i]を昇順ソート
time_needed = [ [f, a * f] for (a, f) in zip(A, F)]
time_needed.sort(key = lambda x:x[1], reverse = True) # a * fで降順にソート

def team_score(K, t_lower, t_upper):
    if t_lower >= t_upper:
        return t_upper
    else:
        t_mid = (t_lower + t_upper) // 2
        n_training = 0  # 時間をt_mid以下にするのに必要な修行の回数
        for i in range(0, N): # 各人に必要な修行回数を足す
            if time_needed[i][1] < t_mid:
                break
            else:
                n_training += math.ceil( (time_needed[i][1] - t_mid) / time_needed[i][0] )

        if n_training == K:
            return t_mid
        elif n_training < K: # もっと修行できる（もっと時間短縮できる「かも」）
            return team_score(K, t_lower, t_mid)
        else: # n_training > K, こんなに修行できない
            return team_score(K, t_mid + 1, t_upper)


print( team_score(K, 0, time_needed[0][1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from math import ceil

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))
    F = sorted(map(int, input().split()), reverse=1)
    CF = sorted(zip(map(int.__mul__, A, F), F), reverse=1)

    search_range_ = [-1, CF[0][0]+1]
    for _ in range((CF[0][0]+1).bit_length()):
        X = sum(search_range_)//2
        search_range = [-1, N]
        for _ in range(N.bit_length()):
            mid = sum(search_range)//2
            search_range[CF[mid][0]<=X] = mid
        CF_ = CF[:search_range[0]+1]
        search_range_[K >= sum(ceil((cf[0]-X)/cf[1]) for cf in CF_) if CF_ else 1] = X 
    return search_range_[1]

        
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

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)

def solve(x):
	total=0
	for i in range(n):
		total+=a[i]-x//f[i]
	return total<=k

#xの範囲 ngは実現が難しい方
ok=a[-1]*f[0]
ng=0

while abs(ok-ng)>1:
	mid=(ok+ng)//2
	if solve(mid):
		ok=mid
	else:
		ng=mid

if solve(ng):
	print(ng)
else:
	print(ok)

Submission status: Wrong Answer

Solution code:
import bisect
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse = True)
d = [[f[i]*a[i], f[i], a[i]] for i in range(n)]
d.sort(reverse = True)
import sys
if len(d) == 1:
    for i in range(n):
        if d[0][2] > 0:
            d[0][2] == 1
        else:
            break
    print(d[0][1]*d[0][2])
    sys.exit()

for i in range(k):
    if d[0][-1] > 0:
        d[0][-1] -= 1
        if d[1][-1] > d[0][-1]:
            d[0][-1], d[1][-1] = d[1][-1], d[0][-1]
            d[0][0] = d[0][1]*d[0][2]
            d[1][0] = d[1][1]*d[1][2]
        else:
            d[0][0] = d[0][1]*d[0][2]
    else:
        break
print(d[0][0])

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().strip().split(' '))
A = sorted(list(map(int, input().strip().split(' '))), reverse=True)
F = sorted(list(map(int, input().strip().split(' '))))
if sum(A) <= K:
  print(0)
  exit()

ng = 0
ok = max([a*f for a,f in zip(A,F)])+1
while True:
  if ok-ng < 2: break
  k = int((ng+ok)/2)
  now_cost = 0
  for a,f in zip(A,F):
    now_cost += a-(k//f)
  if now_cost > K:
    ng = k
  else:
    ok = k
    
print(ok)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from math import ceil

def b_search(MAX, key):
    search_range = [-1, MAX]
    update_range = lambda mid: search_range.__setitem__(key(mid), mid)
    for _ in range(MAX.bit_length()):
        update_range(sum(search_range)//2)
    return search_range

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))
    F = sorted(map(int, input().split()), reverse=1)
    CF = sorted(zip(map(int.__mul__, A, F), F), reverse=1)
    def check(X):
        CF_ = CF[:b_search(N, lambda mid: CF[mid][0]<=X)[0]+1]
        return K >= sum(ceil((cf[0]-X)/cf[1]) for cf in CF_) if CF_ else 1

    return b_search(CF[0][0]+1, check)[1]

        
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

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

Xs = [a*f for a,f in zip(As,Fs)]
X_M = max(Xs)
# print(X_M)
def  binarySearch(l,r,target):
    while r - l > 1:
        mid = (l+r)//2
        """計算を入れる"""
        guess = sum([max(0,a-mid//f) for a,f in zip(As,Fs)])
        # print(mid, guess)
        if guess == target:
            return mid
        if guess < target:
            r = mid
        else:
            l = mid
    return r

print(binarySearch(-1,X_M,K))

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    f = list(map(int, input().rstrip('\n').split()))
    a.sort()
    f.sort(reverse=True)
    left = -1
    right = 10 ** 13
    while right - left > 1:
        mid = (left + right) // 2
        count = 0
        for av, fv in zip(a, f):
            count += max(0, av - (mid // fv))
        if count <= k:
            right = mid
        else:
            left = mid
        print(right, left)
    print(right)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
import numpy as np
s_A = sum(A)
if s_A<=K:
  print(0)
  
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)
mi=0
ma=max(F)*max(A)
while mi+1<ma:
  mid = (mi+ma)//2
  if s_A-np.minimum(A,mid//F).sum()<=K:
    ma=mid
  else:
    mi=mid
  
print(ma)

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    f = list(map(int, input().rstrip('\n').split()))
    a.sort()
    f.sort(reverse=True)
    left = a[0] * f[-1] - 1
    right = a[-1] * f[0] + 1
    while right - left > 1:
        mid = (left + right) // 2
        count = 0
        for av, fv in zip(a, f):
            count += max(0, av - (mid // fv))
        if count <= k:
            right = mid
        else:
            left = mid
    print(right)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    f = list(map(int, input().rstrip('\n').split()))
    a.sort()
    f.sort(reverse=True)
    left = a[0] * f[-1] - 1
    right = a[-1] * f[0] + 1
    print(a)
    print(f)
    while right - left > 1:
        mid = (left + right) // 2
        count = 0
        for av, fv in zip(a, f):
            count += max(0, av - (mid // fv))
        if count <= k:
            right = mid
        else:
            left = mid
    print(right)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
import numpy as np
s_A = sum(A)
if s_A<=K:
  print(0)
  
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)
mi=0
ma=max(F)*max(A)
while mi+1<ma:
  mid = (mi+ma)//2
  print(ma)
  if s_A-np.minimum(A,mid//F).sum()<=K:
    ma=mid
  else:
    mi=mid
  
print(ma)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from math import ceil

def b_search(MAX, key):
    search_range = [-1, MAX]
    update_range = lambda mid: search_range.__setitem__(key(mid), mid)
    for _ in range(MAX.bit_length()+1): update_range(sum(search_range)>>1)
    return search_range

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))
    F = sorted(map(int, input().split()), reverse=1)
    CF = sorted(zip(map(int.__mul__, A, F), F), reverse=1)
    def check(X):
        CF_ = CF[:b_search(N, lambda mid: CF[mid][0]<=X)[0]]
        return K >= sum(ceil((cf[0]-X)/cf[1]) for cf in CF_) if CF_ else 1

    return b_search(CF[0][0]+1, check)[1]

        
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# Aを昇順、Fを降順に並べ替える
# 消化コストの小さい人に食べにくい食べ物を食べてもらう
A.sort()
F.sort()
F=F[::-1]
sumA = A.sum()

def can_eat(x):
  # 全員がx秒以下で食べられるか調べる
  
  # 食べにくさfの食べ物をx秒以内に食べるための消化コストa'は、
  # a' * f <= x  ->  a' <= x / f
  # a'は整数とすると
  # a' = x // f
  
  # 各消化コストaのうち、a'(x秒以下に収めるための消化コスト)を
  # 超えているものについては、a'に収める
  # こうして、x秒以下に収まっている消化コストの配列を作る
  eat_cost_for_x = np.minimum(A, x // F)
  
  # 元の消化コストの合計と、
  # x秒以下に収まっている消化コスト（eat_cost_for_x）の合計を比較し、
  # 修行できる回数(K)以内の差であれば、全員x秒以下で食べられる
  return sumA - eat_cost_for_x.sum() <= K


# 不可能目標（最小でも0秒のため）
left = -1 
# 可能目標 (a <= 10^6, f <= 10^6 なので、a*f <= 10^12)
right = 10**12

# 二分探索でtest(x)がtrueとなるxの最小値を探索する
while left < right:
  mid = (left+right)//2   
  
  # mid秒で食べられる場合は探索範囲の右端をmidにする
  if can_eat(mid):
    right = mid
  # mid秒で食べられない場合は探索範囲の左端をmid+1にする
  else:
    left = mid + 1
 
answer = right
print(answer)

Submission status: Wrong Answer

Solution code:
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

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

high = 0
for x, y in zip(a,f):
    high = max(high, x*y)
low = 0

while high != low:
    mid = int((high + low) // 2)
    tmp = 0
    for x, y in zip(a,f):
        tmp += x - math.floor(mid / y)
        if tmp > k:
            low = mid + 1
            break
    else:
        high = mid
print(high)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().strip().split(' '))
A = sorted(list(map(int, input().strip().split(' '))), reverse=True)
F = sorted(list(map(int, input().strip().split(' '))))
if sum(A) <= K:
  print(0)
  exit()

ng = 0
ok = max([a*f for a,f in zip(A,F)])
while True:
  if ok-ng < 2: break
  k = int((ng+ok)/2)
  now_cost = 0
  for a,f in zip(A,F):
    now_cost += a-((k+(f-k%f))//f)
  if now_cost > K:
    ng = k
  else:
    ok = k
    
print(ok)

Submission status: Wrong Answer

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

ans=int(0)
l.sort()
f.sort()
f.reverse()
t=[]

for i in range(n):

    t.append(l[i]*f[i])

for i in range(k):

    c=t.index(max(t))
    l[c] -=1
    t[c]=l[c]*f[c]
    if not i==0:
        if l[c] < l[c-1]:
            l[c], l[c-1] =l[c-1], l[c]
            t[c-1]=l[c-1]*f[c-1]

ans=max(t)

if ans>=0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# Aを昇順、Fを降順に並べ替える
# 消化コストの小さい人に食べにくい食べ物を食べてもらう
A.sort()
F.sort()
F=F[::-1]
Asum = A.sum()


def can_eat(x):
  # 全員がx秒以下で食べられるか調べる
  
  # 食べにくさfの食べ物をx秒以内に食べるための消化コストa'は、
  # a' * f <= x  ->  a' <= x / f
  # a'は整数とすると
  # a' = x // f
  
  # x秒以下に収めるための修行コストは、
  # a(元の消化コスト) - a'(食べにくさfの食べ物をx秒以内に食べるための消化コスト)
  cost_list = A - x // F
  #print(cost_list)
  
  # x秒以下に収めるための各自の修行コストの合計が、K以下であれば、
  # 全員x秒以下で食べられる
  return cost_list.sum() <= K


# 不可能目標（最小でも0秒のため）
left = -1 
# 可能目標 (a <= 10^6, f <= 10^6 なので、a*f <= 10^12)
right = 10**12

while left+1 < right:
  mid = (left+right)//2
  if can_eat(mid):
    right = mid
  else:
    left = mid
 
answer = right
print(answer)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A = sorted(A)
F = sorted(F, reverse=True)
mul = [A[i]*F[i] for i in range(N)]

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

ma = 2**20
mi = 0
while 1:
    tgt = mi + (ma - mi)//2
    num = 0
    for i in range(N):
        tmp = (mul[i] - tgt + F[i] - 1) // F[i]
        if tmp < 0:
            tmp = 0
        num += tmp
    if ma == mi:
        print(ma)
        exit()
    if num <= K:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2+1

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A = sorted(A)
F = sorted(F, reverse=True)
mul = [A[i]*F[i] for i in range(N)]

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

ma = 2**17
mi = 0
while 1:
    tgt = mi + (ma - mi)//2
    num = 0
    for i in range(N):
        tmp = (mul[i] - tgt + F[i] - 1) // F[i]
        if tmp < 0:
            tmp = 0
        num += tmp
    if ma == mi:
        print(ma)
        exit()
    if num <= K:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2+1

Submission status: Wrong Answer

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

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

ok = 10**12+1
ng = 0

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

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
def bisect_left_withkey(a, x, lo=0, hi=None, key=lambda x: x, keyvalue_x=False):
    left = lo
    right = len(a) if hi is None else hi
    kx = key(x) if keyvalue_x else x
    while left + 1 < right:
        new = (left + right)//2
        kn = key(a[new])
        if kx <= kn:
            right = new
        else:
            left = new
    return right

N, K = inpl()
A = inpl()
F = inpl()
A.sort()
F.sort(reverse=True)
score = [A[i]*F[i] for i in range(N)]

def achievable(m):
    k = 0
    for i in range(N):
        k += max(0, (score[i]-m-1)//F[i] + 1)
        if k > K:
            return False
    return True

M = max(score)
print(bisect_left_withkey(range(M+1), True, key=achievable))

Submission status: Wrong Answer

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

Xs = [a*f for a,f in zip(As,Fs)]
X_M = max(Xs)
# print(X_M)
def  binarySearch(l,r,target):
    while r - l > 1:
        mid = (l+r)//2
        """計算を入れる"""
        guess = sum([max(0,a-mid//f) for a,f in zip(As,Fs)])
        # print(mid, guess)
        if guess == target:
            return mid
        if guess < target:
            r = mid
        else:
            l = mid
    return r

print(binarySearch(-1,X_M,K))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# Aを昇順、Fを降順に並べ替える
# 消化コストの小さい人に食べにくい食べ物を食べてもらう
A.sort()
F.sort()
F=F[::-1]
Asum = A.sum()


def can_eat(x):
  # 全員がx秒以下で食べられるか調べる
  
  # 食べにくさfの食べ物をx秒以内に食べるための消化コストa'は、
  # a' * f <= x  ->  a' <= x / f
  # a'は整数とすると
  # a' = x // f
  
  # x秒以下に収めるための修行コストは、
  # a(元の消化コスト) - a'(食べにくさfの食べ物をx秒以内に食べるための消化コスト)
  cost_list = A - x // F
  
  # x秒以下に収めるための各自の修行コストの合計が、K以下であれば、
  # 全員x秒以下で食べられる
  return cost_list.sum() <= K


# 不可能目標（最小でも0秒のため）
left = -1 
# 可能目標 (a <= 10^6, f <= 10^6 なので、a*f <= 10^12)
right = 10**12

# 二分探索でtest(x)がtrueとなるxの最小値を探索する
while left < right:
  mid = (left+right)//2   
  
  # mid秒で食べられる場合は探索範囲の右端をmidにする
  if can_eat(mid):
    right = mid
  # mid秒で食べられない場合は探索範囲の左端をmid+1にする
  else:
    left = mid + 1
 
answer = right
print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from math import ceil

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))
    F = sorted(map(int, input().split()), reverse=1)
    CF = sorted(zip(map(int.__mul__, A, F), F), reverse=1)

    def check(X):
        return 0
        return K >= sum(ceil((cf[0]-X)/cf[1]) for cf in filter((X,F[0]+1).__lt__ , CF))

    search_range = [-1, CF[0][0]+1]
    update_range = lambda mid: search_range.__setitem__(check(mid), mid)
    for _ in range(search_range[1].bit_length()+1):
        update_range(sum(search_range)>>1)

    return search_range[1]

        
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(int(x) for x in input().split())
f = list(int(x) for x in input().split())
a.sort()
f.sort(reverse=True)

def judge(a, f, x):
    return max([(a*f-x-1)//f+1, 0])

x1, x2 = 0, 0
for i in range(n):
    if x2 < a[i]*f[i]:
        x2 = a[i]*f[i]
while x1 != x2:
    key = (x1+x2)//2
    ans = 0
    for i in range(n):
        ans += judge(a[i], f[i], key)
    if ans == k:
        x1 = key
        break
    elif ans > k:
        x2 = key-1
    else:
        x1 = key+1
print(x1)

Submission status: Wrong Answer

Solution code:
from heapq import *
def abc144c():
  n,k=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  f=sorted(list(map(int,input().split())))[::-1]
  q=[] 
  for i,j in zip(a,f):
    heappush(q,(-i*j,j))
  kk=min(k,10**5)
  for i in range(kk):
    tmp,key=heappop(q)
    heappush(q,(tmp+key,key))
  ans,key=heappop(q)
  if -ans>=0:
    print(-ans)
  else:
    print(0)
abc144c()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from math import ceil

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))
    F = sorted(map(int, input().split()), reverse=1)
    CF = sorted(zip(map(int.__mul__, A, F), F), reverse=1)

    def check(X):
        return K >= sum(ceil((cf[0]-X)/cf[1]) for cf in filter((X,F[0]).__lt__ , CF))

    search_range = [-1, CF[0][0]+1]
    update_range = lambda mid: search_range.__setitem__(check(mid), mid)
    for _ in range(search_range[1].bit_length()+1):
        update_range(sum(search_range)//2)

    return search_range[1]

        
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().strip().split(' '))
A = sorted(list(map(int, input().strip().split(' '))), reverse=True)
F = sorted(list(map(int, input().strip().split(' '))))
if sum(A) <= K:
  print(0)
  exit()

ng = 0
ok = max([a*f for a,f in zip(A,F)])
while True:
  if ok-ng < 2: break
  k = int((ng+ok)/2)
  now_cost = 0
  for a,f in zip(A,F):
    now_cost += a-k//f
    if now_cost > K: break
  if now_cost > K:
    ng = k
  else:
    ok = k
    
print(ok)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))
time = [f[i] * a[-i-1] for i in range(n)]

sup = max([time[i] - f[i] * k // n for i in range(n)] + [0])
inf = 0
while sup > inf:
  x = (sup + inf) // 2
  train = sum([(max([0, time[i] - x]) + f[i] - 1) // f[i] for i in range(n)])
  if k < train:
    inf = x + 1
  else:
    sup = x
print(sup)

Submission status: Wrong Answer

Solution code:
from heapq import *
def abc144c():
  n,k=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  f=sorted(list(map(int,input().split())))[::-1]
  q=[] 
  for i,j in zip(a,f):
    heappush(q,(-i*j,j))
  kk=min(k,10**12);print(kk)
  for i in range(kk):
    tmp,key=heappop(q)
    heappush(q,(tmp+key,key))
  ans,key=heappop(q)
  if -ans>=0:
    print(-ans)
  else:
    print(0)
abc144c()

Submission status: Wrong Answer

Solution code:
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

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

high = 0
if sum(a) > k:
    for x, y in zip(a,f):
        high = max(high, x*y)
low = 0

while high > low + 1:
    mid = int(math.ceil((high + low) / 2))
    tmp = 0
    for x, y in zip(a,f):
        tmp += x - math.floor(mid / y)
        if tmp > k:
            low = mid
            break
    else:
        high = mid
print(high)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A = sorted(A)
F = sorted(F, reverse=True)
count = [0 for elem in A] #
mul = [A[i]*F[i] for i in range(N)]
#print(mul)

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

ma = 2**40
mi = 0
tgt = mi + (ma - mi)//2
while 1:
    tgt = mi + (ma - mi)//2
    #print("tgt:{},{},{}".format(tgt,ma,mi))
    num = 0
    for i in range(N):
        tmp = (mul[i] - tgt + F[i] - 1) // F[i]
        if tmp < 0:
            tmp = 0
        num += tmp
    if ma == mi:
        print(ma)
        exit()
    if (ma-mi) <= 2:
        break
    #tmp = tgt
    if num < tgt:
        ma = mi + (ma - mi)//2-1
    else:
        mi = mi + (ma - mi)//2+1

#print(ma)

for i in range(N):
    tmp = (mul[i] - ma + F[i] - 1) // F[i]
    if tmp < 0:
        tmp = 0
    mul[i] -= F[i]*tmp
    K -= tmp
for k in range(K):
    idx = mul.index(max(mul))
    if mul[idx] == 0:
        break
    mul[idx] -= F[idx]
    count[idx] += 1
print(max(mul))
#print(count)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def prime_decomposition(n): #素因数分解
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  return table

def make_divisors(n): #約数列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def ok(x,p):
    kkk = 0
    for i in range(len(x)):
        kkk += max(0,-(-(x[i][0] - p) // x[i][2]))
    return kkk


n,k = m()
a = l()

f = l()

for i in range(n):
    a[i]


a.sort(reverse = True)

f.sort()
co = 0

d = []

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

d.sort(reverse = True)



ll = 0

rr = d[0][0] 


while True:
    mid = (rr+ll)//2

    if ll == mid:
        break

    if ok(d,mid) <= k:
        rr = mid
    else:
        ll = mid+1

print(ll)

Submission status: Wrong Answer

Solution code:
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

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

high = 0
if sum(a) > k:
    for x, y in zip(a,f):
        high = max(high, x*y)
low = 0

while high > low + 1:
    mid = int(math.ceil((high + low) // 2))
    tmp = 0
    for x, y in zip(a,f):
        tmp += x - math.floor(mid / y)
        if tmp > k:
            low = mid
            break
    else:
        high = mid
print(high)