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 getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

# 3人、5回修行できる
N, K = getNM()
# 消化コスト
A = getList()
# 食べにくさ
F = getList()

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

ng = 0
ok = 10 ** 12 + 1

def judge(limit):
    cnt = 0
    for i in range(N):
        # limit // F[i] 消費コストとして許される値
        # A[i] - (limit // F[i]) 消費コストとして許される値との差
        cnt += max(0, A[i] - (limit // F[i]))
    return cnt

while ok - ng > 1:
    mid = (ok + ng) // 2
    margin = judge(mid)

    # 差がK以下であれば修正可能
    # もうちょい下のmidも試してみる
    if K >= margin:
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

# 3人、5回修行できる
N, K = getNM()
# 消化コスト
A = getList()
# 食べにくさ
F = getList()

A_after = max(sum(A) - K, 0)
left = 0
right = 10 ** 14

for i in range(50):
    mid = (left + right) // 2
    margin = [0] * N

    for i in range(N):
        margin[i] = mid // F[i]

    if sum(margin) >= A_after:
        right = mid
    else:
        left = mid
print(right)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

# 3人、5回修行できる
N, K = getNM()
# 消化コスト
A = getList()
# 食べにくさ
F = getList()

A_after = max(sum(A) - K, 0)
left = 0
right = 10000

for i in range(50):
    mid = (left + right) // 2
    margin = [0] * N

    for i in range(N):
        margin[i] = mid // F[i]

    if sum(margin) >= A_after:
        right = mid
    else:
        left = mid
print(right)

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
a.reverse()
f.sort()
totalnum=sum(a)
maxproduct=0
for i in range(n):
  maxproduct=max(f[i]*a[i],maxproduct)
l1=0
r1=maxproduct
while True:
  l2=l1
  r2=(l1+r1)//2
  if l2==r2:
    break
  counter=0
  for i in range(n):
    c=math.floor(r2/f[i])
    while (c+1)*f[i]<=r2:
      c+=1
    counter+=max(0,a[i]-c)
  if counter<=k:
    r1=r2
  else:
    l1=r2
if l1==r1:
  print(r2)
else:
  counter=0
  r2=r1
  for i in range(n):
    c=math.floor(r2/f[i])
    while (c+1)*f[i]<=r2:
      c+=1
    counter+=max(0,a[i]-c)
  if counter<=k:
    print(r1)
  else:
    print(l1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    F.sort(reverse=True)
    A.sort()
    right=10**12+1
    left=0
    while right-left>1:#区間[left,right)に解Xがある（x以下にできる）
        x=(right+left)//2
        kk=k
        for i in range(n):
            kk-=max(0,A[i]-x//F[i])
        if kk<0:
            left=x+1
        else:
            right=x
    print(left)
    

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    F.sort(reverse=True)
    A.sort()
    right=10**12+1
    left=0
    while right-left>1:#区間[left,right)に解Xがある（x以下にできる）
        x=(right+left)//2
        kk=k
        for i in range(n):
            if A[i]*F[i]<=x:continue
            kk-=A[i]-x//F[i]
            if kk<0:
                left=x+1
                break
        else:
            right=x
    print(left)
    

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    F.sort(reverse=True)
    A.sort()
    right=10**12
    left=0
    while right-left>1:#区間[left,right)に解Xがある（x以下にできる）
        x=(right+left)//2
        kk=k
        for i in range(n):
            if A[i]*F[i]<=x:continue
            kk-=A[i]-x//F[i]
            if kk<0:
                left=x+1
                break
        else:
            right=x
    print(left)
    

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
if sum(A) <= K:
  print(0)
  exit()
A.sort()
F.sort(reverse=True)

l,r = -1,10**12+1

while r-l > 1:
  m = (l+r)//2

  k = 0
  for i in range(N):
    a,f = A[i], F[i]
    k += max(0,a-(m/f))

  if k <= K:
    r = m
  else:
    l = m

print(r)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
if sum(A) <= K:
  print(0)
  exit()
A.sort()
F.sort(reverse=True)

l,r = 0,A[-1]*F[-1]

while r-l > 1:
  m = (l+r)//2

  k = 0
  for i in range(N):
    a,f = A[i], F[i]
    k += max(0, math.ceil(a-(m/f)))

  if k <= K:
    r = m
  else:
    l = m

print(r)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
if sum(A) <= K:
  print(0)
  exit()
A.sort()
F.sort(reverse=True)

l,r = 0,A[-1]*F[-1]

while r-l > 1:
  print(l,r)
  m = (l+r)//2

  k = 0
  for i in range(N):
    a,f = A[i], F[i]
    k += max(0, math.ceil(a-(m/f)))

  if k <= K:
    r = m
  else:
    l = m

print(r)

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)

l,r = 0,A[-1]*F[-1]

while r>=l:
  m = l + (r-l) // 2

  flg = True
  k = K
  for i in range(N):
    a,f = A[i], F[i]
    val = a*f
    while val > m:
      a -= 1
      k -= 1
      val = a * f
    if k < 0:
      flg = False
      break

  if flg and k>=0:
    r = m-1
  else:
    l = m+1

print(l)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
aa = list(map(int, input().split()))
ff = list(map(int, input().split()))

a = sorted(aa, reverse=True)
f = sorted(ff)

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

lb = -1
ub = 10 ** 12 + 1
while (ub - lb) > 1:
    mid = (ub + lb) // 2

    if C(mid) >= 0:
        ub = mid
    else:
        lb = mid
print(ub)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
aa = list(map(int, input().split()))
ff = list(map(int, input().split()))

a = sorted(aa, reverse=True)
f = sorted(ff)

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

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

    lb = 0
    ub = 10 ** 18 + 1
    while (ub - lb) > 1:
        mid = (ub + lb) // 2

        if C(mid) >= 0:
            ub = mid
        else:
            lb = mid
    print(ub)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush

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

# A の大きいものから K 回引く
ahq = []
for i in range(N):
    heappush(ahq, -A[i])
for _ in range(K):
    ax = heappop(ahq)
    if ax < 0:
        ax += 1
    heappush(ahq, ax)

a_list = sorted([-x for x in ahq])
f_list = sorted(F)

#print(a_list, f_list)

# A の小さいものと F の大きいものを組み合わせる
ans = max([a_list[i]*f_list[N-i-1] for i in range(N)])

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush

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

# A の大きいものから K 回引く
ahq = []
for i in range(N):
    heappush(ahq, -A[i])
for _ in range(K):
    ax = heappop(ahq)
    heappush(ahq, ax+1)

a_list = sorted([-x for x in ahq])
f_list = sorted(F)

# A の小さいものと F の大きいものを組み合わせる
ans = max([a_list[i]*f_list[N-i-1] for i in range(N)])

print(ans)

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)

r = 10**10
l = -1

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

def nibutan(low,hi):
    while True:
        ave = (low+hi)//2
        if test(ave):
            hi = ave
        else:
            low = ave
        if hi-low == 1:
            break
    return hi

print(nibutan(l,r))

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)

r = 10**10
l = -1

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

def nibutan(low,hi):
    while True:
        ave = (low+hi)//2
        if test(ave):
            hi = ave
        else:
            low = ave
        if hi-low == 1:
            break
    return hi

print(nibutan(l,r))

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

N, K = MAP()
A = LIST()
B = LIST()
A.sort()
B.sort()

def check(m):
    C = [0] * N
    for i in range(N):
        C[i] = m // B[i]
    res = 0
    for i in range(N):
        res += max(A[i] - C[i], 0)
    return res <= K

res = bisearch_min(-1, INF, check)
print(res)

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

N, K = MAP()
A = LIST()
B = LIST()
A.sort()

def check(m):
    C = [0] * N
    for i in range(N):
        C[i] = m // B[i]
    C.sort()
    res = 0
    for i in range(N):
        res += max(A[i] - C[i], 0)
    return res <= K

res = bisearch_min(-1, 10**9+1, check)
print(res)

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

N, K = MAP()
A = LIST()
B = LIST()
A.sort()

def check(m):
    C = [0] * N
    for i in range(N):
        C[i] = m // B[i]
    C.sort()
    res = 0
    for i in range(N):
        res += max(A[i] - C[i], 0)
    return res <= K

res = bisearch_min(-1, 10**6+1, check)
print(res)

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

N, K = MAP()
A = LIST()
B = LIST()
A.sort()

def check(m):
    C = [0] * N
    for i in range(N):
        C[i] = m // B[i]
    C.sort()
    res = 0
    for i in range(N):
        res += max(A[i] - C[i], 0)
    return res <= K

res = bisearch_min(-1, 2*10**5+1, check)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    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 c(s): # sに対して単調減少
        sum_x = 0
        for i in range(N):
            a,f=A[i],F[i]
            tp = s//f
            if not a <= tp:
                sum_x += a-tp

        return sum_x <= K

    l=-10**20
    r=10**20
    while r-l>1:
        mid = (l+r)//2
        if c(mid):
            r = mid
        else:
            l = mid

    print(r)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N,K = map(int,(input().split()))
A = list(map(int,(input().split())))
F = list(map(int,(input().split())))
A.sort(reverse=True)
F.sort()
time = []
for i in range(N):
    time.append((A[i]*F[i],F[i]))

l = -1
r = 10**12
ans = 0
tmp = -1
while ans != tmp:
    c = 0
    tmp = ans
    for i in range(N):
        if time[i][0] > ans:
            c += (time[i][0] - ans -1)//time[i][1] +1
    if c > K:
        l = ans +1
    else:
        r = ans
    ans = (l+r+1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = LI()
    F = LI()

    # for j in range(20):
    #     print(j, [j//i for i in F])

    # 時間tで感触できるか
    def can_complete(t):
        # 食べものごとの、tに間にあうための消化コスト
        return sum(A)-sum([t//i for i in F])<=K

    ng = -1
    ok = 10**12
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_complete(m):
            ok = m
        else:
            ng = m
    print(ok)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = LI()
    F = LI()

    for j in range(20):
        print(j, [j//i for i in F])

    # 時間tで感触できるか
    def can_complete(t):
        # 食べものごとの、tに間にあうための消化コスト
        return sum(A)-sum([t//i for i in F])<=K

    ng = -1
    ok = 10**12
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_complete(m):
            ok = m
        else:
            ng = m
    print(ok)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = LI()
    F = LI()

    # 時間tで感触できるか
    def can_complete(t):
        # 食べものごとの、tに間にあうための消化コスト
        return sum(A)-sum([t//i for i in F])<=K

    ng = -1
    ok = max(A)*max(F)
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_complete(m):
            ok = m
        else:
            ng = m
    print(ok)

if __name__ == '__main__':
    resolve()

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(reverse=True)
F.sort()


def judge(x):
    val = 0
    for i in range(N):
        val += max(A[i] - x // F[i], 0)
        if val > K:
            return False
    if val <= K:
        return True


ub = 10**12
lb = 0

for i in range(150):
    x = (ub+lb)/2
    if judge(x):
        ub = x
    else:
        lb = x
    if ub - lb < 0.5:
        break

print(int(x))

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(reverse=True)
F.sort()


def judge(x):
    val = 0
    for i in range(N):
        val += max(A[i] - x // F[i], 0)
        if val > K:
            return False
    if val <= K:
        return True


ub = 10**12
lb = 0

for i in range(80):
    x = (ub+lb)/2
    if judge(x):
        ub = x
    else:
        lb = x

print(int(x))

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(reverse=True)
F.sort()


def judge(x):
    val = 0
    for i in range(N):
        val += max(A[i] - x // F[i], 0)
        if val > K:
            return False
    if val <= K:
        return True


ub = 10**12
lb = 0

for i in range(50):
    x = (ub+lb)/2
    if judge(x):
        ub = x
    else:
        lb = x

print(int(x))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc144/tasks/abc144_e


# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる

# 求めたいのは最大値！
# 最小はxにできると仮定してみる？
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort()  # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)])  # ここから崩すことができるポイントを探せる

from math import ceil


def is_ok(x, K):
    for i in range(N):
        if A[i] * F[i] <= x:
            continue
        a = ceil(A[i] - x / F[i])  # Kから使うべき個数
        K -= a
        if K < 0:
            return False
    return K > -1


def meguru_bisect(ng, ok):
    '''
    define is_okと
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, K):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(-1, 10**6 + 1))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc144/tasks/abc144_e


# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる

# 求めたいのは最大値！
# 最小はxにできると仮定してみる？
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort()  # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)])  # ここから崩すことができるポイントを探せる


def is_ok(x, K):
    for i in range(N):
        if A[i] * F[i] <= x:
            continue
        a = A[i] - (x // F[i])  # Kから使うべき個数
        K -= a
        if K < 0:
            return False
    return K > -1


def meguru_bisect(ng, ok):
    '''
    define is_okと
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, K):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(-1, 10**6 + 1))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc144/tasks/abc144_e


# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる

# 求めたいのは最大値！
# 最小はxにできると仮定してみる？
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort()  # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)])  # ここから崩すことができるポイントを探せる


def is_ok(x, K):
    for i in range(N):
        if A[i] * F[i] < x:
            continue
        a = A[i] - (x - 1) // F[i]  # Kから使うべき個数
        K -= a
        if K < 0:
            return False
    return True


def meguru_bisect(ng, ok):
    '''
    define is_okと
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, K):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(-1, 10**6 + 1) - 1)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc144/tasks/abc144_e


# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる

# 求めたいのは最大値！
# 最小はxにできると仮定してみる？
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort()  # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)])  # ここから崩すことができるポイントを探せる


def is_ok(x, K):
    for i in range(N):
        if A[i] * F[i] <= x:
            continue
        a = A[i] - (x - 1) // F[i]  # Kから使うべき個数
        K -= a
        if K < 0:
            return False
    return True


def meguru_bisect(ng, ok):
    '''
    define is_okと
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, K):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(-1, 10**6 + 1) - 1)

Submission status: Wrong Answer

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

def test(x):
    return np.maximum(0,a-x//f).sum() <= k

def nibutan(low,hi):
    while True:
        ave = (low+hi)//2
        #ここの条件式を問題文に合わせる
        if test(ave):
            hi = ave
        else:
            low = ave
        if hi - low == 1:
            break
    li = [low,hi]
    return li

li = nibutan(0,10**12)

print(li[1])

Submission status: Wrong Answer

Solution code:
#k回消化コストを-1できる

n,k=map(int,input().split())
#消化コスト
a=list(map(int,input().split()))
a.sort()
#食べにくさ
f=list(map(int,input().split()))
f.sort(reverse=True)

#食べやすいものを消化コストが高い人
#食べにくいものを消化コストが低い人にしたほうがいい
#kをどこで減らすかは2部探索
#a-ans//f の和がk以下で、最小のans

ll=1
rr=10**18

result=10**18
while ll+1<rr:
    ans=(rr+ll)//2
    
    cnt=0
    for i in range(n):
        cnt+=max(0,a[i]-ans//f[i])
    if cnt<=k:
        rr=ans
    else:
        ll=ans
#ansが小さくなると、cntが大きくなる



print(rr)

Submission status: Wrong Answer

Solution code:
#k回消化コストを-1できる

n,k=map(int,input().split())
#消化コスト
a=list(map(int,input().split()))
a.sort()
#食べにくさ
f=list(map(int,input().split()))
f.sort(reverse=True)

#食べやすいものを消化コストが高い人
#食べにくいものを消化コストが低い人にしたほうがいい
#kをどこで減らすかは2部探索
#a-ans//f の和がk以下で、最小のans

ll=0
rr=10**18

result=10**18
while ll<rr:
    ans=(rr+ll)//2
    
    cnt=0
    for i in range(n):
        cnt+=max(0,a[i]-ans//f[i])
    if cnt<=k:
        rr=ans
    else:
        ll=ans+1
#ansが小さくなると、cntが大きくなる



print(ans)