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: Accepted

Solution code:
import subprocess
import gzip, base64, os
import stat

gz = b'H4sIABTqtl0C/+19C3hTVbbwSfoKryYgagXU6lRtVUoDBVpASSmRcyQtSAsiPg5pmtJommSSEyjKS1scj6GKM86M1ztzx3vv6HjnnzvjjC90F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IW8z6OxhI7NvTpqh2Uueh4MRurlZDHnDkWDA7feB7MUlqVF5lgkf/PODvoFBLI0jmGdTUt3cwBJMh3O8kWgTVlVZCfgSqtwE8hN6b5oRAxpgIssGaeYv40JRyelJowQEfBVMvdx3QPKDWb9+FIf+FFraF372Uu2cDvXXj/u+AEfT5v8FglQOuumbAAA='
bin = gzip.decompress(base64.b64decode(gz))
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
with open(pymain, "wb") as f:
    f.write(bin)
os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if p == "":
    pymain = "./" + pymain
subprocess.call(pymain)


# compiled by pythran
'''
#pythran export main2()
import numpy as np
i8 = np.int64
i4 = np.int32


def solve(A, F, K):
    min_ = 0
    max_ = 10 ** 12
    while min_ < max_:
        mid = (min_ + max_) // 2
        count = A - mid // F
        sum_ = count[count > 0].sum()
        if sum_ <= K:
            max_ = mid
        else:
            min_ = mid + 1
    return min_


def main2():
    stdin = open('/dev/stdin')
    N, K = np.fromstring(stdin.readline(), i8, -1, ' ')
    A = np.fromstring(stdin.readline(), i8, -1, ' ')
    F = np.fromstring(stdin.readline(), i8, -1, ' ')
    A = np.sort(A)[::-1]
    F = np.sort(F)
    ans = solve(A, F, K)
    print(ans)
'''

Submission status: Accepted

Solution code:
import numpy as np
N, K= map(int, input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]

A=np.array(sorted(A, reverse=True))
F=np.array(sorted(F))

lower_bound=0
upper_bound=np.max(A*F)
K_tmp=0

while upper_bound>=lower_bound:
    mid=(lower_bound+upper_bound)//2
    K_tmp=np.sum(np.maximum(A-mid//F, 0))
    if K_tmp<=K:
        upper_bound=mid-1
    else:
        lower_bound=mid+1

print(lower_bound)

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, k = LMIIS()
    a = LMIIS()
    f = LMIIS()
    a.sort(reverse=True)
    f.sort()


    max_ = 10**12
    min_ = 0

    while max_ != min_ + 1:
        x = (max_ + min_) // 2
        shugyo = 0
        for i in range(n):
            shugyo += max(0, a[i] - x // f[i])

        if shugyo <= k:
            max_ = x
        else:
            min_ = x


    if x == min_:
        x += 1
    if sum(a) <= k:
        x = 0
    print(x)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]
F = [int(f) for f in input().split()]

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

if K >= sum(A):
    ans = 0
else:
    u = 10**13
    l = 0
    while u-l > 1:
        x = (u+l)//2
        cnt = K
        for i in range(N):
            cnt -= max(0, A[i]-x//F[i])
        if cnt >= 0:
            u = x
        else:
            l = x
    cnt = K
    for i in range(N):
        cnt -= max(0, A[i]-l//F[i])
    if cnt >= 0:
        ans = l
    else:
        ans = u
        
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, k = LMIIS()
    aa = LMIIS()
    ff = LMIIS()
    aa.sort(reverse=True)
    ff.sort()
    a = tuple(aa)
    f = tuple(ff)


    max_ = 10**12
    min_ = 0

    while max_ != min_ + 1:
        x = (max_ + min_) // 2
        shugyo = 0
        for i in range(n):
            shugyo += max(0, a[i] - x // f[i])

        if shugyo <= k:
            max_ = x
        else:
            min_ = x


    if x == min_:
        x += 1
    if sum(a) <= k:
        x = 0
    print(x)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def isOK(mid,N,K,sort_F,sort_A):
    cnt = 0
    for i in range(N):
        cnt += max(sort_A[i] - (mid // sort_F[i]),0)
    return cnt <= K

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    sort_A = sorted(A)
    sort_F = sorted(F, reverse=True)

    ng = -1
    ok = 10 ** 12 + 5
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOK(mid,N,K,sort_F,sort_A):
            ok = mid
        else:
            ng = mid

    print(ok)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
I = np.array([int(_) for _ in open(0).read().split()])
N, K = I[0], I[1]
A, F = I[2:2 + N], I[2 + N:2 + 2 * N]
A = np.sort(A)
F = np.sort(F)[::-1]
lb = -1
rb = 10**13


# Min x for check(x) == True
def check(x):
    if np.sum(np.maximum(A - np.array([x]) // F, 0)) <= K:
        return 1
    else:
        return 0


while rb - lb > 1:
    mid = (rb + lb) // 2
    if check(mid):
        rb = mid
    else:
        lb = mid
print(rb)

Submission status: Accepted

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  = np.sort(np.array(a))
f = np.sort(np.array(f))[::-1]

l ,r = 0, 10 ** 12
while l <= r:
 x = (l + r) // 2
 if np.clip(a - x // f, 0, None).sum() <= k:
  r = x - 1
 else:
  l = x + 1
print(l)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
import heapq
import math

def main():
    N, K = map(int, input().split())
    A = [int(c) for c in input().split()]
    F = [int(c) for c in input().split()]
    
    A.sort()
    F.sort(reverse=True)

    num = 0
    sum_ = []
    for i in range(len(A)):
        sum_.append(A[i] * F[i])
    left = 0
    right = 10 ** 12
    while(num < 50):
        number = 0
        mid = (left + right) // 2
        # print(mid)
        for i in range(len(A)):
            if sum_[i] <= mid:
                continue
            else:
                number += math.ceil((sum_[i] - mid) / F[i])
            # print(number)
        if number > K:
            # 最大値をmidより小さくできない -> 最大値はもっとでかい
            left = mid + 1
        else:
            right = mid
        num += 1
    print(mid)
                

if __name__ == '__main__':
    main()

Submission status: Accepted

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)

start = -1
end = A[-1] * F[0]

def check(now):
    cnt = 0
    for a, f in zip(A, F):
        eatable = now//f
        if eatable < a:
            cnt += a - eatable
    if cnt > K:
        return False
    return True

while end > start + 1:
    now = (start + end) // 2
    if check(now):
        end = now
    else:
        start = now

print(end)

Submission status: Accepted

Solution code:
import sys
import math
import bisect
 
 
sys.setrecursionlimit(1000000000)
def input():
    return sys.stdin.readline().strip()
 
def iinput():
    return int(input())
 
def finput():
    return float(input())
 
def tinput():
    return input().split()
 
def rinput():
    return map(int, tinput())
 
def rlinput():
    return list(rinput())
 
def modst(a, s):
    res = 1
    while s:
        if s % 2:
            res *= a
        a *= a
        s //= 2
    return res

 
def main():
    n, k = rinput()
    a = sorted(rlinput())
    s = sorted(rlinput())
    l, res = -1, 10 ** 12
    while res - l > 1:
        m = (res + l) // 2
        q = k    
        for i in range(n):
            w = a[i] - (m // s[- i - 1])
            q -= max(0, w)
        if q < 0:
            l = m
        else:
            res = m
    print(res)        
main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
# from bisect import *
from collections import *
from heapq import *
# import itertools
import math
# INF = 10**9
# MOD = 10**9+7

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
F = [int(x) for x in input().split()]
F.sort(reverse = 1)
l, r = -1, 10**12
while l+1 < r:
    x = (l+r)//2
    c = 0
    for a, f in zip(A, F):
        if a*f > x:
            c += max(0,a-x//f)
    if c > K:
        l = x
    else:
        r = x
print(r)

Submission status: Accepted

Solution code:
def p(F,A,s): # スコアをsにするために最小限必要な修行の回数
    res=0
    for i in range(N):
        res+=max(A[i]-s//F[i],0)
    return res

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

F.sort(reverse=True) # 降順で固定
A.sort() # 昇順で固定

l=0
r=max([F[i]*A[i] for i in range(N)])

while r-l>1:
    m=(l+r)//2
    if p(F,A,m)<=K:
        r=m
    else:
        l=m

print(r if p(F,A,0)>K else 0)

Submission status: Accepted

Solution code:
def p(F,A,s): # スコアをsにするために最小限必要な修行の回数
    res=0
    for i in range(N):
        res+=max(A[i]-s//F[i],0)
    return res

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

F.sort(reverse=True) # 降順で固定
A.sort() # 昇順で固定

l=0
r=max([F[i]*A[i] for i in range(N)])

while r-l>1:
    m=(l+r)//2
    if p(F,A,m)<=K:
        r=m
    else:
        l=m

if r>1 or p(F,A,0)>K:
    ans=r
else:
    ans=0

print(ans)