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:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()

C = [None] * N
for i, (a, f) in enumerate(zip(A, F)):
    C[i] = (a * f, f)


def solve(x):
    global K, N
    t = 0
    for c, f in C:
        temp = ((c - x) + f - 1) // f
        t += max(0, temp)
        if t > K:
            result = False
            break
    else:
        result = True
    return result


ok = A[0] * F[N - 1]
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid


print(ok)

Submission status: Accepted

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

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

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

def check(v):
    ans = 0
    for i in range(N):
        ans += max(A[i] - v//F[i],0)
    return ans<=K

if check(0):
    print(0)
else:
    l = 0
    r = 10**12 + 1
    while r-l>1:
        if check((l+r)//2):
            r = (l+r)//2
        else:
            l = (l+r)//2
    print(r)

Submission status: Accepted

Solution code:
from math import ceil

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

def is_valid(A, F, K, T):
    for a, f in zip(A, F):
        if a*f > T:

            k = ceil(a - T/f)
            if k <= K:
                K -= k
            else:
                return False
    return True

def solve(N, K, A, F):
    i = 0
    left, right = 0, 10**12

    while left < right:
        mid = (left + right) // 2

        if is_valid(A, F, K, mid):
            right = mid
        else:
            left = mid + 1
    
    if is_valid(A, F, K, mid-1) and (not is_valid(A, F, K, mid)):
        return mid-1
    elif is_valid(A, F, K, mid):
        return mid
    else:
        return mid+1

print(solve(N, K, A, F))

Submission status: Accepted

Solution code:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# 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)
def main(x):
    _K=K
    for i in range(N):
        a=A[i]-x//F[i]
        if a>0:
            _K-=a
            if _K<0:
                return(0)
    return(1)


end=10**12
if main(0):
    print(0)
    exit()
else:
    st=0

while end-st>1:
    now=(end+st)//2
    if main(now):
        end=now
    else:
        st=now

if main(st):
    print(st)
else:
    print(end)

Submission status: Accepted

Solution code:
def main():
    import numpy as np
    import sys
    input = sys.stdin.readline
    N, K = map(int,input().split())
    A = np.sort(list(map(int,input().split())))
    F = np.sort(list(map(int,input().split())))[::-1]

    if K >= np.sum(A)*N:
        print(0)
        exit()
    ma = A[-1]*F[0]
    mi = 0
    A = A*F
    while ma != mi:
        tgt = (ma + mi)//2
        tmp = np.ceil((A-tgt)/F)
        if np.sum(tmp[tmp>0]) <= K:
            ma = (ma + mi)//2
        else:
            mi = (ma + mi)//2+1
    print(ma)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import numpy as np
    import sys
    input = sys.stdin.readline
    N, K = map(int,input().split())
    A = np.sort(list(map(int,input().split())))
    F = np.sort(list(map(int,input().split())))[::-1]
    mul = A*F
    if K >= np.sum(A)*N:
        print(0)
        exit()

    ma = A[-1]*F[0]
    mi = 0
    while ma != mi:
        tgt = (ma + mi)//2
        num = np.sum(np.maximum(0,(mul-tgt+F-1)//F))
        if num <= K:
            ma = (ma + mi)//2
        else:
            mi = (ma + mi)//2+1
    print(ma)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
A = np.sort(list(map(int,input().split())))
F = np.sort(list(map(int,input().split())))[::-1]
mul = A*F
if K >= np.sum(A)*N:
    print(0)
    exit()

ma = A[-1]*F[0]
mi = 0
while ma != mi:
    tgt = (ma + mi)//2
    tmp = np.ceil((mul-tgt)/F)
    num = np.sum(tmp[tmp>0])
    if num <= K:
        ma = (ma + mi)//2
    else:
        mi = (ma + mi)//2+1
print(ma)

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
A = np.sort(list(map(int,input().split())))
F = np.sort(list(map(int,input().split())))[::-1]
mul = A*F
if K >= sum(A)*N:
    print(0)
    exit()

ma = 2**40
mi = 0
while ma != mi:
    tgt = (ma + mi)//2
    tmp = np.ceil((mul-tgt)/F)
    num = np.sum(tmp[tmp>0])
    if num <= K:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2+1
print(ma)

Submission status: Accepted

Solution code:
def is_ok(x):
    trainings = 0
    for i in range(N):
        t = A[i] - x // F[i]
        if t > 0:
            trainings += t
    return trainings <= K


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

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

ng = -1
ok = A[-1] * F[0]
while ok - ng > 1:
    m = ng + (ok - ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
F = sorted(list(map(int,input().split())),reverse=True)
high = 0
for i in range(N):
    high = max(high,A[i]*F[i])
low = -1
while high-low>1:
    mid = (high+low)//2
    flag = 1
    T = K
    for i in range(N):
        if A[i]*F[i]<=mid:continue
        else:
            T -= math.ceil(A[i]-mid/F[i])
            if T<0:
                flag = 0
                break
    if flag==1:
        high = mid
    else:
        low = mid
print(high)

Submission status: Accepted

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

A = sorted(A)[::-1]
F = sorted(F)

sumA = sum(A)

if sumA <= K:
    print(0)
else:
    maxC = 0
    for i in range(N):
        tmp = A[i]*F[i]
        if maxC < tmp:
            maxC = tmp
    L = 0
    R = maxC
    visited = {}
    visited[maxC]=True
        
    while 1:
        nowC = (L+R)//2
        nowA = []
        for i in range(N):
            nowA.append(nowC//F[i])
        shugyou = 0
        for i in range(N):
            shugyou += max(A[i]-nowA[i],0)
        if shugyou <= K:
            visited[nowC] = True
            R = nowC
            if (nowC-1) in visited:
                if visited[nowC-1] == False:
                    ans = nowC
                    break
        else:
            visited[nowC] = False
            L = nowC
            if (nowC+1) in visited:
                if visited[nowC+1] == True:
                    ans = nowC+1
                    break
                
        if nowC == 0:
            if visited[nowC]==True:
                ans = 0
                break
    print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def bs(f, mi, ma):
    mm = -1
    while ma > mi:
        mm = (ma+mi) // 2
        if f(mm):
            mi = mm + 1
        else:
            ma = mm
    if f(mm):
        return mm + 1
    return mm

def main():
    n,k = LI()
    a = sorted(LI())
    b = sorted(LI(), reverse=True)
    if sum(a) <= k:
        return 0

    def f(i):
        t = 0
        for ai,bi in zip(a,b):
            u = i // bi
            if ai > u:
                t += ai - u
        return t > k

    r = bs(f,0,10**12)

    return r


print(main())

Submission status: Accepted

Solution code:
from math import ceil
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
l=[]
for i in range(n):
  l.append([f[i]*a[i],a[i],f[i]])
l.sort()
ng=-1
ok=l[n-1][0]
while ok-ng>1:
  mid=(ok+ng)//2
  cnt=0
  for i in range(n):
    if l[i][0]>mid:
      cnt+=ceil((l[i][0]-mid)/l[i][2])
  if cnt<=k:
    ok=mid
  else:
    ng=mid
print(ok)

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)
def ok(p):
  result = 0
  for i in range(n):
    result += max(a[i]-p//f[i],0)
  if result <= k:
    return True
  return False

L = 0
U = a[-1]*f[0]
while U-L >= 1:
  M = (U+L)//2
  if ok(M):
    U = M
  else:
    L = M+1
    
print(U)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())))[::-1]
r = 10**12+1
l = -1
while r - l > 1:
    s = k
    mid = (r + l)//2
    for i, j in zip(a, f):
        if mid < i*j:
            s -= i-mid//j
    if s < 0:
        l = mid
    else:
        r = mid
#    print('r:', r, 'l:', l, 'r-l:', r-l)
print(r)

Submission status: Accepted

Solution code:
def p_e():
    n, k = map(int, input().split())
    *A, = map(int, input().split())
    *F, = map(int, input().split())
    A.sort()
    F.sort(reverse=True)

    def check(x):
        count = 0
        for a, f in zip(A, F):
            count += max(a - x // f, 0)
        return count <= k

    max_num = 0
    for a, f in zip(A, F):
        if max_num < a * f:
            max_num = a * f
    l, h = 0, max_num
    while l <= h:
        mid = (l + h) // 2
        if check(mid):
            h = mid - 1
        else:
            l = mid + 1
    print(h + 1)
    
p_e()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    F=list(map(int,input().split()))
    F.sort(reverse=True)
    
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(mid):
        k=0
        for i in range(N):
            k+=max(0,-(-(A[i]*F[i]-mid)//F[i]))
        if k<=K:
            return True
        else:
            return False
    
    print(nibutan(10**18,-1))
        
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

import math

N, K = ints()
A = list(sorted(ints()))
F = list(reversed(sorted(ints())))
AF = [A[i]*F[i] for i in range(N)]

afmax = max(AF)

def can(seiseki):
  k = K
  for i in range(N):
    af = AF[i]
    if af>seiseki:
      k -= math.ceil((af-seiseki)/F[i])
      if k<0:
        return False
  return k>=0

l = -1
r = afmax
while r-l>1:
  m = (l+r)//2
  if can(m):
    r = m
  else:
    l = m
print(r)

Submission status: Accepted

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

k = max(sum(a)-k,0)

a.sort()
f.sort()
f.reverse()

# rは100%満たす。lは100%満たさない
l = -1
r = a[-1]*f[0]*2

while l+1!=r:
    x = (l+r)//2
    b = []
    for i in range(n):
        b.append(min(x//f[i], a[i]))
    if k<=sum(b):
        r=x
    else:
        l=x

print(r)

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)
l=-1
r=10**13
while r-l!=1:
    m=(l+r)//2
    x=0
    for i in range(N):
        x+=max(0,A[i]-m//F[i])
    if x<=K:
        r=m
    else:
        l=m
print(r)

Submission status: Accepted

Solution code:
import math

#成績xを取れるか？xに関して二分探索

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)
AF=[0]*N

for i in range(N):
    AF[i]=A[i]*F[i]
    
ng=-1
ok=10**12+1

#二分探索，成績xをとるのにi番目の人が何回修行すべきか，これがK以下なら良い
while ok-ng!=1:
    x = (ok+ng)//2
    num_tra =0
    for i in range(N):
        af_i = int(math.ceil((AF[i]-x)/F[i]))
        if af_i>0:
            num_tra+=af_i
    if num_tra<=K:
        ok=x
    else:
        ng=x
        
print(ok)

Submission status: Accepted

Solution code:
def main():
    import numpy as np
    n, k = map(int, input().split())
    aa = np.array(sorted(list(map(int, input().split()))), dtype=np.int64)
    f = np.array(sorted(list(map(int, input().split())),
                        reverse=True), dtype=np.int64)

    a = 0
    b = 10**12+10
    while a+1 < b:
        med = (a+b)//2
        if np.sum(np.maximum(aa-med//f, np.zeros(n, dtype=np.int64))) > k:
            a = med+1
        else:
            b = med
    if a == b:
        print(a)
    else:
        if np.sum(np.maximum(aa-a//f, np.zeros(n, dtype=np.int64))) > k:
            print(b)
        else:
            print(a)


main()

Submission status: Accepted

Solution code:
import numpy as np
def solve(n, k, a, f):
    a = sorted(a)
    f = sorted(f)[::-1]
    a = np.asarray(a, dtype=int)
    f = np.asarray(f, dtype=int)
    total = np.sum(a)
    l = -1
    r = np.max(a*f)
    while r - l > 1:
        th = (l + r) // 2
        cost = total - np.minimum(a, th // f).sum()
        if cost <= k:
            r = th
        else:
            l = th
    return r

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
print(solve(n, k, a, f))

Submission status: Accepted

Solution code:
import sys
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,K=LI()
As=LI()
As.sort()
Fs=LI()
Fs.sort(reverse=True)

rgt = 10**12
lft = 0
while lft < rgt:
    cost = K
    half = (lft + rgt) // 2
    for i in range(N):
        if As[i]*Fs[i] > half:
            cost -= (As[i]*Fs[i] - half) // Fs[i]
            cost -= 1 if (half - As[i]*Fs[i]) % Fs[i] > 0 else 0

    if cost < 0:
        lft = half + 1
    else:
        rgt = half
    # print(lft, rgt)

print(rgt)

Submission status: Accepted

Solution code:
n,k=map(int,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 score(x):
    syugyo = 0
    for A,F in zip(a,f):
        sup = x//F
        if sup < A:
            syugyo += A-sup
    if syugyo <= k:
        return True
    return False


left = 0
right = a[-1]*f[0]+1
while left < right-1:
    mid = (left+right)//2
    if score(mid):
        right = mid
    else:
        left = mid
print(left+1 if left != 0 else 0)

Submission status: Accepted

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

l = -1     #スコアが絶対この値より大きくなる数値から始める。
r = 10**13 #スコアが絶対この値より小さくなる数値から始める。
while(l+1<r):
  m = (l+r)//2
  t = 0
  for i in range(N):
    t += max(A[i]-m//F[i],0)
  #print(l,m,r,t)
  if t <= K:
    r = m
  else:
    l = m
print(r)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))[::-1]
l,r=10**12+1,-1
while l-r>1:
    t=(l+r)//2
    s=k
    for i,j in zip(a,b):
        if t<i*j:s-=i-t//j
    if s<0:r=t
    else:l=t
print(l)

Submission status: Accepted

Solution code:
import copy
import math
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort()
A.reverse()
maxX = max(F) * max(A)
def is_able(low, up):
    target = (low + up) // 2
    if low == up - 1:
        return up
    if check(target):
        return is_able(low, target)
    else:
        return is_able(target, up)
def check(time):
    #time が可能かどうか
    practice = copy.deepcopy(k)
    for i in range(n):
        if A[i] * F[i] > time:
            practice -= A[i] - math.floor(time / F[i]) 
            if practice < 0:
                return False
    return True
print(is_able(-1, maxX))

Submission status: Accepted

Solution code:
import sys
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
Flist = list(map(int,input().split()))
Alist.sort()
sum_Alist = 0
for i in range(N):
    sum_Alist += Alist[i]
print(Alist,Flist,file=sys.stderr)
if sum_Alist <= K:
    print(0)
    exit()
maxtime = max(Alist)*max(Flist)
mintime = -1
print(maxtime,mintime,file=sys.stderr)
midlist = [0 for i in range(N)]
while mintime+1 < maxtime:
    mid = (mintime+maxtime)//2
    sum_midlist = 0
    max_midlist = 0
    for i in range(N):
        midlist[i] = mid//Flist[i]
    midlist.sort()
    for i in range(N):
        if midlist[i] < Alist[i]:
            sum_midlist += Alist[i]-midlist[i]
    #print(maxtime,mintime,sum_midlist,file=sys.stderr)
    if sum_midlist <= K:
        maxtime = mid
    else:
        mintime = mid
print(maxtime)

Submission status: Accepted

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.sort()
F.sort()
F = F[::-1]
dig = A.sum()


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


l = -1
r = 10 ** 18 + 1

while l + 1 < r:
    test = (l + r) // 2
    if judge(test):
        r = test
    else:
        l = test

print(r)

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)
af = [[ai * fi, ai, fi] for ai, fi in zip(a, f)]
af.sort()
def calc(cand):
    cost = 0
    for afi, ai, fi in af:
        if cand < afi:
            cost += ai - cand // fi
            if cost > k:
                return False
    return True

left = 0
right = af[-1][0]
while True:
    mid = (right + left) // 2
    if mid == left:
        if calc(left):
            print(left)
        else:
            print(right)
        break
    if calc(mid):
        right = mid
    else:
        left = mid

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if(discrete) else 10**-8
    if((not left)^f(r)): return r if(left) else r+1
    elif(left^f(l)): return l-1 if(left) else l
    while(r-l>eps):
        h=(l+r)//2 if(discrete) else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if(not discrete) else l if(left) else r

def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    A.sort()
    F.sort(reverse=1)

    def check(m):
        cost=0
        for a,f in zip(A,F):
            if(a*f<=m): continue
            cost+=a-(m//f)
        return cost<=k

    print(bisection(0,10**12,check,left=False))
resolve()

Submission status: Accepted

Solution code:
import numpy as np

def main():
    N, K = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    F = np.array(list(map(int, input().split())))

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

    time = A*F
    high = 10**12 + 1
    low = -1

    while high - low > 1:
        middle = (high + low) // 2

        temp = np.where(time>middle, time-middle, 0)
        temp = np.ceil(temp/F).sum()

        if temp <= K:
            high = middle
        else:
            low = middle

    print(high)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

def main():
    N, K = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    F = np.array(list(map(int, input().split())))

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

    time = A*F
    high = 10**12 + 1
    low = -1

    while high - low > 1:
        middle = (high + low) // 2

        temp = np.where(time>middle, time-middle, 0)
        temp = np.ceil(temp/F).sum()

        if temp <= K:
            high = middle
        else:
            low = middle

    middle = high
    temp = np.where(time>middle, time-middle, 0)
    temp = np.ceil(temp/F)
    time = (time - temp*F).max()
    print(int(time))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Solution code:
import math
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()
    hi = a[0] * f[-1]
    lo = 0
    def caneat(m):
        t = 0
        for i, j in zip(a, f):
            if i * j > m:
                t += math.ceil((i*j - m)/j)
            if t > k:
                return False
        return True
    while hi != lo:
        m = (hi + lo) // 2
        if caneat(m):
            hi = m
        else:
            lo = m + 1
    return hi
print(main())

Submission status: Accepted

Solution code:
import numpy as np

def is_ok(mid, k):
    s = np.maximum(a - mid // f, 0).sum()
    if s <= k:
        return True
    else:
        return False

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
f = np.array(list(map(int, input().split())))
a = np.sort(a)
f = np.sort(f)[::-1]

l, r = -1, np.max(a * f) # l:ng, r:ok
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, k):
        r = mid
    else:
        l = mid
print(r)

Submission status: Accepted

Solution code:
import numpy as np

def is_ok(mid, k):
    s = np.maximum(a - mid // f, 0).sum()
    if s <= k:
        return True
    else:
        return False

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
a = np.array(a)
f = np.array(f)

l, r = -1, np.max(a * f) # l:ng, r:ok
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, k):
        r = mid
    else:
        l = mid
print(r)

Submission status: Accepted

Solution code:
import numpy as np

def is_ok(mid, k):
    s = a - mid // f
    s = s[s > 0].sum()
    if s <= k:
        return True
    else:
        return False

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
a = np.array(a)
f = np.array(f)

l, r = -1, 10**12 # l:ng, r:ok
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, k):
        r = mid
    else:
        l = mid
print(r)

Submission status: Accepted

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

def count(mid):
    res = 0
    for a, f in zip(A, F):
        t = (a*f - mid)
        if t < 0: continue
        res += int(math.ceil(t/f))
    return res
  
start, end = 0, max(a*f for a, f in zip(A, F))
while start + 1 < end:
    mid = (start + end)//2
    if count(mid) <= K:
        end = mid
    else:
        start = mid
if count(start) <= K:
    print(start)
else:
    print(end)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = sorted(list(map(int, readline().split())))
    f = sorted(list(map(int, readline().split())), reverse=True)

    cor_v = 10 ** 19
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for av, fv in zip(a, f):
            afv = av * fv
            if afv > bin_v:
                cost += (afv - bin_v + fv - 1) // fv
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if not discrete else l if left else r

def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    F=list(map(int,input().split()))
    F.sort(reverse=1)

    def check(m):
        cost=0
        for a,f in zip(A,F):
            if(a*f<=m): continue
            cost+=(a*f-m-1)//f+1
        return cost<=k

    print(bisection(0,10**12,check,left=False))
resolve()

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()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
l=0
r=10**12
x=(r+l)//2
def check(x):
    p=0
    for i in range(n):
        if x//f[i]<a[i]:
            p+=a[i]-x//f[i]
            if p>k:
                return False
    if p>k:
        return False
    else:
        return True
while l+1<r:
    if check(x):
        r=x
        x=(r+l)//2
    else:
        l=x
        x=(r+l)//2
print(r)

Submission status: Accepted

Solution code:
import numpy as np


def solve():
    N, K = map(int, input().split())
    a_l = np.array(input().split(), int)
    b_l = np.array(input().split(), int)
    a_l.sort()
    b_l.sort()
    b_l = b_l[::-1]

    sum_a = a_l.sum()
    left, right = -1, 10**13
    while left + 1 < right:
        mid = (left + right) // 2
        if sum_a - np.minimum(a_l, mid // b_l).sum() <= K:
            right = mid
        else:
            left = mid

    print(right)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
import queue
bbn=1000000007
	
#+++++

def can_finish(time, a_c_qq, a_k):
	kc=a_k
	
	#if time==12:
	#	print(*a_c_qq)
		
	for (st,a,f) in (a_c_qq):
		if st <= time:
			return True
		
		#time => f*a' を目指す。
		#a' <= time / f が必要。
		#コストは a - (time // f)
		kc -= a - (time//f)
		#if time==12:
		#	pa((st,a,f, time,(time//f),a- (time//f),kc))
		
		if kc < 0:
			return False
		
	return True
	
		
def main():
	n, k = map(int, input().split())
	al=list(map(int, input().split()))
	fl=list(map(int, input().split()))
	
	qq=queue.PriorityQueue()
	
	al.sort(reverse=True)
	fl.sort()
	qq=[(a*f,a,f) for a,f in zip(al,fl)]
	qq.sort(reverse=True)

	#while not qq.empty():
	#	a=qq.get()
	#	pa(a)
	
	ok_max,_,_=qq[0]
	if sum(al) <= k:
		return 0
	ng_min=0
	
	while ok_max - ng_min > 1:
		mid = (ok_max + ng_min)// 2
		can_do = can_finish(mid, qq, k)
		#pa((ok_max,ng_min,mid,can_do))
		if can_do:
			ok_max = mid
		else:
			ng_min = mid

	print(ok_max)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l1=sorted(l1)
l2=sorted(l2)
l2=l2[::-1]
l3=[]
for i in range(n):
  l3.append(l1[i]*l2[i])
left=0
right=10**12
while left<right:
  mid=(left+right)//2
  if mid==left:
    num=0
    for i in range(n):
      if l3[i]<=left:
        pass
      else:
        dis=l3[i]-left#いくつ減らす必要がある？
        num+=((dis-1)//l2[i])+1
    if num<=k:
      print(left)
      exit()
    else:
      print(right)
      exit()
  num=0
  for i in range(n):
    if l3[i]<=mid:
      pass
    else:
      dis=l3[i]-mid
      num+=((dis-1)//l2[i])+1
  if num<=k:
    right=mid
  else:
    left=mid
print(left)