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:
from math import ceil
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 check(m):
    used = 0
    for i in range(N):
        b = ceil(A[i]-m/F[i])
        if b < 0:
            b = 0
        if A[i]-b < 0:
            return False
        used += b
        if used > K:
            return False 
    return True
left = -1
right = A[-1]*F[0]
while right-left > 1:
    mid = (right+left)//2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)

Submission status: Accepted

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()<=b:
    y=mid
  else:
    x=mid
print(y)

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 shugyou_count(X):
    # 目標スコアをXとしたときの必要修行回数を求める
    count = 0
    for a, f in zip(A, F):
        count += max(0, a - X // f)
    return count


# 二分探索で達成可能な最小値を見つける
l = -1
r = max(A) * max(F)
while l + 1 < r:
    X = (l + r) // 2
    if shugyou_count(X) <= K:
        r = X
    else:
        l = X
print(r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np


def is_ok(mid, K, A, F):
    return np.maximum(A - mid // F, 0).sum() <= K


def main():
    N, K = input_line(int, int)
    A = input_line([int])
    F = input_line([int])
    A = np.array(sorted(A))
    F = np.array(sorted(F, reverse=True))

    ng = -1
    ok = int(1e12)
    while ok - ng > 1:
        mid = (ng + ok) // 2
        if is_ok(mid, K, A, F):
            ok = mid
        else:
            ng = mid
    print(ok)


def input_line(*types):
    if isinstance(types[0], list):
        return [types[0][0](x) for x in input().split()]
    elif len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        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, r = -1, 10 ** 12
        while l + 1 < r:
            mid = (l + r) // 2

            s = 0
            for i in range(N):
                s += max(0, A[i] - mid // F[i])
            if s <= K:
                r = mid
            else:
                l = mid
        print(r)


# Run main
if __name__ == '__main__':
    AtCoder().main()

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]

l = 0
r = (A * F).max()

while l < r:
    m = (l + r) // 2
    if np.maximum(A - m // F, 0).sum() <= K:
        r = m
    else:
        l = m + 1

print(r)

Submission status: Accepted

Solution code:
import numpy as np

N, K = map(int, input().split())
A = np.sort(list(map(int, input().split())))
F = np.sort(list(map(int, input().split())))[::-1]

l, r = 0, 10**12
m = (l + r) // 2

while True:
  if np.maximum(A - m//F, 0).sum() <= K:
    r = m
  else:
    l = m
  
  m = (l + r) // 2
  if r == l + 1:
    if np.maximum(A - l//F, 0).sum() <= K:
      x = l
    else:
      x = r
    break

print(x)

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))
F=np.array(sorted(f, reverse=True))
left=-1
right=10**12
while left+1<right:
    x=(left+right)//2
    if np.maximum(A-x//F , 0).sum()<=k:
        right=x
    else:
        left=x
print(right)

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についても、修行前の大小で並べてしまって良いです
A=np.array(sorted(a))
F=np.array(sorted(f, reverse=True))
#最大値の最小化▶︎二分探索！
#答えxを決めて、A*Fペア全てをx以下にするために必要な修行がk回以下かを調べていく。(xについて二分探索)
left=-1
right=10**12
s=A.sum()
#A-x//Fは、x以下にするのに必要な最小の修行回数。
#np.maximum(A-x//F,0)は、２つの配列の大きい方を取っていきながらあたらしい配列を作っている。
while left+1<right:
    x=(left+right)//2
    if np.maximum(A-x//F , 0).sum()<=k:
        #この時答えはx以下なので
        right=x
    else:
        #この時答えはxより大きいので
        left=x
print(right)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
aa.sort()
bb.sort(reverse=True)

low=0
high=max([aa[i]*bb[i] for i in range(n)])
while low<high and abs(high-low)>=2:
    mid=(low+high)//2
    tot=0
    for i in range(n):
        a=mid//bb[i]
        ans=max(aa[i]-a,0)
        tot+=ans
    #print(mid,tot)
    if tot<=k:
        high=mid
    else:
        low=mid+1

for i in range(low,high+1):
    tot=0
    for ii in range(n):
        a=i//bb[ii]
        ans=max(aa[ii]-a,0)
        tot+=ans
   # print(i,tot)
    if tot<=k:
        ans=i
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
n, k = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))
f = list(map(int, sys.stdin.readline().strip().split()))

a = sorted(a)  # 昇順ソート
f = sorted(f, reverse=True)  # 降順ソート


def team_result(a, f):
    eat = []
    for i, j in zip(a, f):
        eat.append(i * j)
    return(max(eat))


r = team_result(a, f)
l = -1  # l = 0 はあり得るので
while(l + 1 < r):
    mid = (l + r) // 2

    train_cost = 0
    for i, j in zip(a, f):
        train_cost += max(0, math.ceil(i - mid / j))

    if train_cost <= k:
        r = mid
    else:
        l = mid

print(r)

Submission status: Accepted

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


def ok(mid,a,b,k,n):
    tmp = 0
    for i in range(n):
        if a[i] * b[i] > mid:
            tmp += a[i] - mid//b[i]
    if tmp > k:
        return 1
    else:
        return -1


def bin_search(a,b,k,n):
    l = 0
    r = 10**12
    while l <= r:
        mid = l + (r - l)//2
        res = ok(mid,a,b,k,n)
        if res < 0:
            r = mid - 1
        else:
            l = mid + 1
    return l


print(bin_search(a,b,k,n))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N, K = mis()
    A = lmis()
    A.sort(reverse=True)
    F = lmis()
    F.sort()
    #
    class solver:
        def __getitem__(self, score_limit):
            k = K
            for i in range(N):
                if A[i]*F[i] > score_limit:
                    k -= A[i] - score_limit//F[i]
                    if k < 0:
                        return False
            return True
    #
    import bisect
    print(bisect.bisect_left(solver(), True, hi=A[0]*F[-1]))

main()

Submission status: Accepted

Solution code:
import heapq
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
F = list(map(int, sys.stdin.readline().split()))

if N == 1:
    a = A[0]
    f = F[0]
    ans = max(a - K, 0) * f
    print(ans)
    exit()

A = np.array(A, dtype=int)
F = np.array(F, dtype=int)
A.sort()
F.sort()
F = F[::-1]


def required_k(score):
    # score を出すために必要な K
    return np.ceil(np.maximum(A - score / F, 0)).sum()


ok = (A * F).max()
ng = -1
while abs(ok - ng) > 1:
    score = (ok + ng) // 2
    if required_k(score) <= K:
        ok = score
    else:
        ng = score
print(ok)

Submission status: Accepted

Solution code:
import math
n,k = map(int, input().split())
alst = list(map(int, input().split()))
flst = list(map(int, input().split()))

sorted_flst = sorted(flst, key = lambda x: -x)
sorted_alst = sorted(alst)

pair_lst = []
for a, b in zip(sorted_flst, sorted_alst):
    pair_lst.append((a*b, a))
sorted_pair_lst = sorted(pair_lst, key = lambda x:-x[0])

def judge(sorted_pair_lst, x):
    cnt = 0
    for pair in sorted_pair_lst:
        if pair[0] <= x:
            return True
        else:
            cnt += math.ceil((pair[0] - x) / pair[1])
            if cnt > k:
                return False
    return True

low = 0
high = 10**15
while high - low > 1:
    middle = (low+high) // 2
    if judge(sorted_pair_lst, middle):
        high = middle
    else:
        low = middle
print(low) if judge(sorted_pair_lst, low) else print(high)

Submission status: Accepted

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

Solution code:
# -*- coding: utf-8 -*-
import sys

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
F=map(int, sys.stdin.readline().split())
A.sort(reverse=True)
F.sort()

max_ans=10**12

def check(temp_ans):
    if temp_ans<0:
        return False
    k=0
    for a,f in zip(A,F):
        if a*f<=temp_ans: continue
        aa=temp_ans/f
        k+=(a-aa)
        if K<k:
            return False
    else:
        return True

h=max_ans
l=-1

while h-l!=1:
    m=(h+l)/2
    if check(m):
        h=m
    else:
        l=m

print h

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
F=map(int, sys.stdin.readline().split())
A.sort(reverse=True)
F.sort()

max_ans=A[0]*F[-1]

def check(temp_ans):
    if temp_ans<0:
        return False
    k=0
    for a,f in zip(A,F):
        if a*f<=temp_ans: continue
        aa=temp_ans/f
        k+=(a-aa)
        if K<k:
            return False
    else:
        return True

h=max_ans
l=-1

while h-l!=1:
    m=(h+l)/2
    if check(m):
        h=m
    else:
        l=m

print h

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
s = A.sum()
l = -1
r = 10**12
while l+1 < r:
    m = (l+r) // 2 
    # 全てのA、Fにつき、Aとm//Fで小さい方の合計がK以下
    # m//Fは修行したあとの消化コスト
    if s - np.minimum(A, m//F).sum() <= K:
      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()))

a.sort()
f.sort()
f.reverse()
x=0
for i in range(n):
    y=a[i]*f[i]
    x=max(x,y)

l=-1
r=x
z=0
while l+1<r:
    mid =(l+r)//2
    for i in range(n):
        if a[i]*f[i]<=mid:
            continue
        else:
            z+=-(-(a[i]*f[i]-mid)//f[i])
    if z<=k:
        r=mid
        z=0
    else:
        l=mid
        z=0
print(r)

Submission status: Accepted

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()<=b:
    y=mid
  else:
    x=mid
print(y)

Submission status: Accepted

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

left = -1
right = 10**18+1
 
 
while right - left > 1:
    mid = left + (right - left) // 2
 
 
    train = k
    for i in range(n):
        req = mid // f[i]
        if req < a[i]:
            train -= a[i] - req
 
 
    if train >= 0:
        right = mid
    else:
        left = mid
 
 
 
print(right)

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)

ng = -1
ok = 10 ** 12

while ok - ng > 1:
	mid = (ok + ng) // 2
	ctr = 0
	for i in range(N):
		ctr += max(0, A[i] - mid // F[i])
	if ctr <= K:
		ok = mid
	else:
		ng = mid

print(ok)

Submission status: Accepted

Solution code:
import numpy as np

n,k = map(int, input().split())
lstA = np.array(sorted(list(map(int, input().split()))))
lstF = np.array(sorted(list(map(int, input().split())), reverse=True))
s = lstA.sum()

left = -1
right = 10**12

while True:
    center = (left+right)//2
    if s-np.minimum(lstA, center//lstF).sum() <=k:
        right = center
    else:
        left = center
    if right <= left+1:
        print(right)
        exit()

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)
ok = 10**12
ng = -1

while ok-ng>1:
  X = (ok+ng)//2
  tmp = 0
  for i in range(N):
    tmp += max(A[i]-X//F[i],0)
  if tmp<=K:
    ok = X
  else:
    ng = X
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)
ok = 10**12
ng = -1

while ok-ng>1:
  X = (ok+ng)//2
  tmp = 0
  for i,e in enumerate(A):
    tmp += max(e-X//F[i],0)
  if tmp<=K:
    ok = X
  else:
    ng = X
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)


ng = -1
ok = 10**12
while ok-ng > 1:
    mid = (ok+ng)//2
    cnt = 0

    for i,e in enumerate(a):    
        cnt += max(0,e-mid//f[i])
    if cnt <= k:
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Accepted

Solution code:
def main():
    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()
    a = a[::-1]
    f.sort()
    right = np.max(a*f)
    left = 0
    while right > left:
        middle = (right + left)//2
        if np.sum(np.maximum(a-middle//f, 0)) <= k:
            right = middle
        else:
            left = middle+1
    print(right)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():

    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()
    a = a[::-1]
    f.sort()
    right = np.max(a*f)
    left = 0
    while right > left:
        middle = (right + left)//2
        b = 0
        
        if np.sum(np.maximum(a-middle//f, 0)) <= k:
            right = middle
        else:
            left = middle+1

    print(right)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
N,K=map(int,input().split())
A=np.array(sorted(list(map(int,input().split()))))
F=np.array(sorted(list(map(int,input().split())), reverse=True))
s=A.sum()
l=-1
r=10**12+2
while l+1<r:
    m=(l+r)//2
    if s-np.minimum(A,m//F).sum()<=K:
        r=m
    else:
        l=m
print(r)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
# a = [int(x) for x in input().split()]
# f = [int(x) for x in input().split()]
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
lx = -1
rx = a[-1] * f[0]
while rx-lx>1 :
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        kk += max(0, a[j] - cx//f[j])
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)

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()
a = a[::-1]
left = -1
right = np.max(a * f)
while left + 1 < right:
    mid = (left + right) // 2
    if np.sum(np.maximum(a - mid // f, 0)) <= k:
        right = mid
    else:
        left = mid

print(right)

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)
#print(a)
#print(f)
scale = 42
aim = 2 ** scale -1
gap = 2 ** (scale-1)
while True:
  train = 0
  for i in range(n):
    train += max(0, a[i] - aim//f[i])
  if gap == 0:
    if train <= k:
      print(aim)
    else:
      print(aim+1)
    break
  #print(aim,gap,train)
  if train <= k:
    aim -= gap
    gap //= 2
  else:
    aim += gap
    gap //= 2

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

if sum(A) < K:
    K = sum(A)

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

left = 0
right = 10 ** 12
while left < right:
    mid = (left + right) // 2
    G = A - (mid // F)
    if G[G>0].sum() <= K:
        right = mid
    else:
        left = mid + 1

print(right)

Submission status: Accepted

Solution code:
from math import ceil
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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

low = 0
high = A[-1]*F[0]

while low <= high:
    mid = (low+high)//2
    train = K
    for a, f in zip(A, F):
        if a*f > mid:
            need_train = ceil((a*f-mid)/f)
            if train >= need_train:
                train -= need_train
            else:
                low = mid+1
                break
    else:
        high = mid-1
print(low)

Submission status: Accepted

Solution code:
import sys


def solve():
    sys.setrecursionlimit(2000)
    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)

    cor_v = 10 ** 13
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            cost += max((a[i] * f[i] - bin_v + f[i] - 1) // f[i], 0)
        #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 numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

if sum(A) < K:
    K = sum(A)

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

left = 0
right = 10 ** 12
while left < right:
    mid = (left + right) // 2
    sum = 0
    G = A - (mid // F)
#    for i in range(N):
#        sum += max(0, G[i])
    if G[G>0].sum() <= K:
        right = mid
    else:
        left = mid + 1

print(right)

Submission status: Accepted

Solution code:
import math
import numpy as np


def main():
    s = input().split(" ")
    N = int(s[0])
    K = int(s[1])
    A = np.array([int(a) for a in input().split(" ")])
    F = np.array([int(a) for a in input().split(" ")])
    A = np.sort(A)
    F = np.sort(F)[::-1]
    AF = A * F
    m = np.max(AF)

    if(func(0, AF, F, N, K)):
        print(0)
        return
    a = 0
    b = m
    for aaa in range(m):
        if((b - a) <= 1):
            print(b)
            return
        mid = int((b - a) / 2.) + a
        if(func(mid, AF, F, N, K)):
            b = mid
        else:
            a = mid
    print("???????")


def func(saidai, AF, F, N, K):
    count = np.sum(np.ceil((AF[(AF - saidai) > 0] - saidai) / F[(AF - saidai) > 0]))
    return count <= K


if(__name__ == "__main__"):
    main()

Submission status: Accepted

Solution code:
import numpy as np

N,K = map(int,input().split())
A = np.sort(list(map(int,input().split())))
F = np.sort(list(map(int,input().split())))[::-1]

Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        AF = A-xm//F 
        if np.sum(AF[AF>0]) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Submission status: Accepted

Solution code:
import numpy as np
from math import ceil

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.sort()

if np.sum(A) <= K:
    print(0)
else:
    st = 0
    ed = 10 ** 12
    md = ceil((st + ed) / 2)
    while True:
        if np.sum(A - np.minimum(A, md // F[::-1])) <= K:
            ed = md
        else:
            st = md
        md = ceil((st + ed) / 2)

        if md == ed:
            break

    print(md)

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int,input().split())
A = np.array(sorted(map(int,input().split())))
F = np.array(sorted(map(int,input().split()) ,reverse=True))
low,high = -1, int(1e12)
while high-low>1:
  mid = (high+low)//2
  k = (A-np.minimum(A,mid//F)).sum()
  if k>K: low = mid
  else: high = mid
print(high)

Submission status: Accepted

Solution code:
import numpy as np
N,K = map(int,input().split())
A = np.array(list(map(int,input().split())))
F = np.array(list(map(int,input().split())))
A = np.sort(A)
F = np.sort(F)[::-1]
Asum = A.sum()

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

left = -1
right = np.amax(A * F)

while right - left > 1:
    mid = (right + left)//2
    if test(mid) == 1:
        right = mid
    else:
        left = mid
print(right)

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)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k: right = mid
    else: left = mid

print(right)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
alist = list(map(int,input().split()))
flist = list(map(int,input().split()))
alist.sort()
flist.sort(reverse = True)
L = -1
R = 10 ** 18
while R-1 > L:
  mid = (R +L)//2
  count = 0
  loop_count = 0
  for i in flist:
    if alist[loop_count] > mid // i:
      count += alist[loop_count] - mid // i
    loop_count += 1
  if count > k:
    L = mid
  else:
    R = mid
print(R)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
a = inpl()
f = inpl()
a.sort()
f.sort(reverse=True)
l = -1
r = 10**18

def sol(x):
    cnt = 0
    for i in range(n):
        cnt += max(0, a[i] - x//f[i])
    # print(cnt)
    if cnt <= k:
        return True
    else:
        return False

while l + 1 < r:
    mid = (l+r)//2
    if sol(mid):
        r = mid
    else:
        l = mid
    # print(mid)
print(r)

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]

t_max = A[-1] * F[0]
t_min = -1

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

print(t_max)

Submission status: Accepted

Solution code:
import numpy as np
N, train_max = map(int, input().split())
members = np.sort(list(map(int, input().split())))
members_sum = members.sum()
foods = np.sort(list(map(int, input().split())))[::-1]

inferenced_time_max = int(1e+6 * 1e+6)
inferenced_time_min = -1

while inferenced_time_max > inferenced_time_min+1:
  inferenced_time = (inferenced_time_max + inferenced_time_min) // 2
  inferenced_members = np.minimum(members, inferenced_time // foods)
  if members_sum - inferenced_members.sum() <= train_max:
    inferenced_time_max = inferenced_time
  else:
    inferenced_time_min = inferenced_time

print(inferenced_time_max)

Submission status: Accepted

Solution code:
import numpy as np

N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
f=list(map(int,input().split()))
ff=sorted(f, reverse=True)
F=np.array(ff)
#F = np.array(sorted(list(map(int, input().split()))))
#F = F[::- 1]

left = - 1
right = 10**12

'''
l=10//F
print(A)
print(l)
print(A[A>l])
print(A[A>l].sum())
'''

def f(x):
    l = x//F
    return A[A > l].sum() <= K + l[A > l].sum()
    

 
while right - left > 1:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid
    
print(right)

Submission status: Accepted

Solution code:
def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    f = list(map(int,input().split()))
    a.sort()
    f.sort(reverse=True)
    ok = 10**12
    ng=-1

    while ok-ng>1:
        mid=(ok+ng)//2
        cnt=0
        for x,y in enumerate(a):
            cnt+=max(0,y-mid//f[x])
        if cnt>k:
            ng=mid
        else:
            ok=mid
    print(ok)
main()

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)
w=[0,0]
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=50
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<a[i]-ws//f[i]:
            p=-1
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws//f[i]
    if p>=0:
        w[1]=ws
    else:
        w[0]=ws
print(w[1])

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
s = A.sum()
l = -1
r = 10**12 # 取りうる最大は10**6 * 10**6 で10**12
# 全てのa*fが答えとなる数以下にできるかを10**12から二分探索
while l+1 < r:
    m = (l+r) // 2 # こここそが二分探索の肝で、ありえん小さい数とありえん大きい数から始めて半分にして狭めていく
    # 全てのA、Fにつき、Aとm//Fで小さい方の合計がK以下
    # m//Fは修行したあとの消化コスト
    # mが大きすぎてnp.minimum(A, m//F)がすべてAを選ぶならその合計は0なのでK以下が成り立つ
    # その場合、r=mとしてrを減らして再計算
    # K以下は修行に余力を残した状態か、修行できてないか。それより上のmはありえないのでr = mとする
    if s - np.minimum(A, m//F).sum() <= K:
        r = m
    # 修行ポイント以上に修行してしまった場合、それ未満のmはありえないのでl = mとする
    else:
        l = m
print(r)

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
s = A.sum()
l = -1
r = 10**12+2
# 全てのa*fが答えとなる数以下にできるかを10**12から二分探索
while l+1 < r:
    m = (l+r) // 2 # こここそが二分探索の肝で、ありえん小さい数とありえん大きい数から始めて半分にして狭めていく
    # 全てのA、Fにつき、Aとm//Fで小さい方の合計がK以下
    # m//Fは修行したあとの消化コスト
    # mが大きすぎてnp.minimum(A, m//F)がすべてAを選ぶならその合計は0なのでK以下が成り立つ
    # その場合、r=mとしてrを減らして再計算
    # K以下は修行に余力を残した状態か、修行できてないか。それより上のmはありえないのでr = mとする
    if s - np.minimum(A, m//F).sum() <= K:
        r = m
    # 修行ポイント以上に修行してしまった場合、それ未満のmはありえないのでl = mとする
    else:
        l = m
print(r)

Submission status: Accepted

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

Submission status: Accepted

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