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:
import math
N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))[::-1]
Cs = [a*b for a, b in zip(As, Bs)]
BCs = list(zip(Bs, Cs))

def func(target):
    r = 0
    for b, c in BCs:
        r += math.ceil(max(0, c - target) / b)
    return r <= K

if __name__ == '__main__':
    min_i, max_i, index = 0, max(Cs)+1, 1
    while True:
        if func(index):
            index, max_i = (index-1 + min_i)//2, index-1
            continue
        index, min_i = (index+1 + max_i)//2, index+1
        if min_i == max_i:
            print(min_i)
            break

Submission status: Wrong Answer

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

cnt = 0
memo = 0
for i in reversed(range(N-1)):
    cnt += A[i + 1] - A[i] + cnt
    if cnt >= K:
        memo = i
        break
if cnt < K:
    print(0)
    exit()
A[memo] = A[memo] - (cnt - K)
tmp = 0
for i in range(memo + 1):
    tmp = max(tmp, A[i] * F[memo - i + 1])
print(tmp)

Submission status: Wrong Answer

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

cnt = 0
memo = 0
for i in reversed(range(N-1)):
    cnt += A[i + 1] - A[i] + cnt
    if cnt >= K:
        memo = i
        break
if cnt < K:
    print(cnt)
    print(0)
    exit()
A[memo] = A[memo] - (cnt - K)
tmp = 0
for i in range(memo + 1):
    tmp = max(tmp, A[i] * F[memo - i])
print(tmp)

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)
#Amax = A[-1]
Amax = max(A)
Fmax = F[0]
As = sum(a for a in A)

x=0
if As < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    xm = int((xl+xh)//2)
    Asum2 = 0
    while xh-xl > 0:
        Asum2 = sum(xm//f for f in F)
        if As-Asum2 > K:
            xl = xm + 1
        else:
            xh = xm
        xm = int((xl+xh)//2)
    x = xl
print(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()
F.sort(reverse = True)
Amax = A[-1]
Fmax = F[0]
As = sum(a for a in A)

x=0
if As < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    xm = int((xl+xh)//2)
    Asum2 = 0
    while xh-xl > 0:
        chk = [A[i]-xm//F[i]>=0 for i in range(0,N)]
        if False in chk:
            xh = xm - 1
        else:
            Asum2 = sum(xm//f for f in F)
            if As-Asum2 > K:
                xl = xm + 1
            else:
                xh = xm - 1
        xm = int((xl+xh)//2)
    x = xh + 1
print(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()
F.sort(reverse = True)
Amax = A[-1]
Fmax = F[0]
As = sum(a for a in A)

x=0
if As < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    xm = int((xl+xh)//2)
    Asum2 = 0
    while xh-xl > 0:
        Asum2 = sum(xm//f for f in F)
        if As-Asum2 > K:    
            xl = xm + 1
        else:
            xh = xm - 1
        xm = int((xl+xh)//2)
    x = xh + 1
print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()])
F = np.array([int(x) for x in input().split()])
A.sort()
Asum=np.sum(A)
F.sort();F=F[::-1]
left=-1 #不可能
right=10**10 #可能
while left+1<right:
  mid =(left+right)//2
  if Asum-np.minimum(A,mid//F).sum()<=K:
    right=mid
  else:
    left=mid
print(right)

Submission status: Wrong Answer

Solution code:
import numpy as np
#import math
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))



left = - 1
right = 10**12

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

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

Submission status: Wrong Answer

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

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 ** 7)
INF = 10 ** 18
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(reverse=True)
B.sort()

def check(m):
    k = 0
    for i, a in enumerate(A):
        b = B[i]
        k += ceil(a - m/b)
    return k <= K

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

def main():
    n, k = map(int, input().strip().split())
    a = sorted(list(map(int, input().strip().split())))
    f = sorted(list(map(int, input().strip().split())), reverse=True)

    l = -1
    r = 10**12
    while l+1 < r:
        mid = (l + r) // 2
        if sum(max(0, a[i] - mid/f[i]) for i in range(n)) <= k:
            r = mid
        else:
            l = mid
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort(reverse=True)
f.sort()
z = zip(a,f)
ok = max(x*y for x,y in z)
ng = -1
while ok-ng>1:
  mid = (ok+ng)//2
  if sum(x-mid//y for x,y in z if x*y > mid) <= k:
    ok = mid
  else:
    ng = mid
print(ok)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort(reverse=True)
f.sort()
z = zip(a,f)
ok = max(x*y for x,y in z)
ng = -1
while ok-ng>1:
  mid = (ok+ng)//2
  if sum(max(0,x-mid//y) for x,y in z) <= k:
    ok = mid
  else:
    ng = mid
print(ok)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort(reverse=True)
f.sort()
z = zip(a,f)
ok = max(x*y for x,y in z)
ng = -1
while ok-ng>1:
  mid = (ok+ng)//2
  if sum(max(0,x-y//mid) for x,y in z) <= k:
    ok = mid
  else:
    ng = mid
print(ok)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC144 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
from itertools import product
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f_x(x):
    s = 0
    for A,F in zip(a,f):
        s += max(0,A - x/F)
    if s <= k:
        return True
    return False


n,k = LI()
a = LI()
f = LI()
a.sort()
f.sort(reverse = True)
ok,ng = 10**12,-1
while ok - ng > 1:
    mid = (ok + ng)//2
    if f_x(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC144 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
from itertools import product
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f_x(x):
    s = 0
    for A,F in zip(a,f):
        s += max(0,A - x/F)
    if s <= k:
        return True
    return False


n,k = LI()
a = LI()
f = LI()
if sum(a) <= k:
    print(0)
    quit()
a.sort()
f.sort(reverse = True)
ok,ng = 10**20,0
while ok - ng > 1:
    mid = (ok + ng)//2
    if f_x(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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**12
while l+1 < r: 
    m = (l + r) //2
    S = 0
    for i in range(N):
        S += A[i] - min((m / F[i]), A[i])
    if S <= 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)
Amax = A[-1]
Fmax = F[0]
AsK = sum(a for a in A)-K
if AsK < 1:
    x = 0
else:
    x1 = 0
    x2 = Amax*Fmax
    while True:
        Asum1 = sum(x1//fi for fi in F)
        Asum2 = sum(x2//fi for fi in F)
        if Asum1 < AsK and Asum2 >= AsK:
            if x1+1==x2:
                x = x2
                break
            else:
                x2b = x2
                x2 = int((x1+x2)//2)
                continue
        elif Asum1 < AsK and Asum2 < AsK:
            x1 = x2
            x2 = x2b
            continue
print(x)

Submission status: Wrong Answer

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

def judge(t):
    global a,F,N,K
    K_t=K
    for i in range(N):
        target=t//F[i]
        if a[i]<=target:
            continue
        if K_t>=a[i]-target:#引けるかどうか
            K_t-=a[i]-target
        else:
            return False
    return True

t_max=a[-1]*F[0] #絶対True
t_min=-1 #絶対False
while t_max>t_min+1:
    t_mid=(t_max+t_min)//2
    if judge(t_mid):
        t_max=t_mid
    else:
        t_min=t_mid
print(t_max)

Submission status: Wrong Answer

Solution code:
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=0
    right=10**12
    while left + 1 < right:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
    print(right)

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

Submission status: Wrong Answer

Solution code:
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=0
    right=10**12
    while True:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
        if right-left<=1:
            break
    print(right)

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

Submission status: Wrong Answer

Solution code:
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=0
    right=10**12
    prev_x=-10
    # 二分探索でtest(x)がtrueとなるxの最小値を探索する
    # left = rightとなるまで繰り返す
    while left + 1 < right:
      mid = (left+right)//2
      
      # mid秒で食べられる場合は探索範囲の右端をmidにする
      if can_eat_by(mid):
        right = mid
      # mid秒で食べられない場合は探索範囲の左端をmidにする
      else:
        left = mid
     
    answer = right
    print(answer)

main()

Submission status: Wrong Answer

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)
ans=0
for i in range(n):
    ans=max(ans,max(0,a[i]-k)*f[i])
    k=max(0,k-a[i])
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 = max(a)* max(f)
l = -1

while r-l >1:
    c = (r+l) //2
    ans=0
    for j in range(n):
        ans += max(a[j]- c / f[j] , 0)
    if ans <= k:
        r = c
    else:
        l = c

print(r)

Submission status: Wrong Answer

Solution code:
import sys
n, k = map(int, input().split())
l=list(map(float, input().split()))
f=list(map(float, input().split()))
if sum(l)<=k:
    print(0)
    sys.exit()
ans=int(0)
l.sort()
f.sort()
f.reverse()
m=l[0]*f[0]
for i in range(n):
    if m<l[i]*f[i]:
        m=l[i]*f[i]

ok=int(m)
ng=int(0)
while True:
    a=int(0)
    mid=int((ok + ng)//2)
    if ok-ng==1:
        break

    for i in range(n):
        if mid//f[i]<=l[i]:
            a +=mid//f[i]
        else:
            a += l[i]

    if a>=sum(l)-k:
        ok=mid
        ans=ng
    else:
        ng=mid
        ans=ok
print(ans)

Submission status: Wrong Answer

Solution code:
# E - Gluttony
def isOK(c, N, K, A, F):
    s = 0
    for i in range(N):
        s += max(0, A[i] - c / F[i])
    return s <= K
    
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort()
F.reverse()

l = -1
r = 10 ** 12
while l + 1 < r:
    c = int((l + r) / 2)
    ok = isOK(c, N, K, A, F)
    if ok:
        r = c
    else:
        l = c
    
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()))

AsK = sum(a for a in A)-K
Fs = sum((1/f) for f in F)

if AsK < 1:
    print(0)
else:
    x = int(-(-AsK//Fs))
    print(x)

Submission status: Wrong Answer

Solution code:
import sys
n, k = map(int, input().split())
l=list(map(float, input().split()))
f=list(map(float, input().split()))
if sum(l)<=k:
    print(0)
    sys.exit()
ans=int(0)
l.sort()
f.sort()
f.reverse()
t=[]

for i in range(n):

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


ok=int(max(t))
ng=int(0)
while True:
    k1=k
    mid=int((ok + ng)//2)
    if ok-ng==1:
        break


    for i in range(n):
        if t[i]>mid:
            k1=k1-(((t[i]-mid-0.5))//f[i]+1)

    if k1<0:
        ng=mid
        ans=ok
    else:
        ok=mid
        ans=ng

print(ans)

Submission status: Wrong Answer

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

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

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

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

print(mid)

Submission status: Wrong Answer

Solution code:

n, k = map(int, input().split())
l=list(map(float, input().split()))
f=list(map(float, input().split()))

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

for i in range(n):

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


ok=int(max(t))
ng=int(0)
while True:
    k1=k
    mid=int((ok + ng)//2)
    if ok-ng==1:
        break


    for i in range(n):
        if t[i]>mid:
            k1=k1-(((t[i]-mid-0.5))//f[i]+1)

    if k1<0:
        ng=mid
        ans=ok
    else:
        ok=mid
        ans=ng


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

Submission status: Wrong Answer

Solution code:

n, k = map(int, input().split())
l=list(map(float, input().split()))
f=list(map(float, input().split()))

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

for i in range(n):

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

print(l)
print(f)
print(t)

ok=int(max(t))
ng=int(0)
while True:
    k1=k
    mid=int((ok + ng)//2)
    if ok-ng==1:
        break

    print(mid)
    for i in range(n):
        if t[i]>mid:
            k1=k1-(((t[i]-mid-0.5))//f[i]+1)
        print(k1)
    if k1<0:
        ng=mid
        ans=ok
    else:
        ok=mid
        ans=ng
    print("ok=" + str(ok))
    print("ng="+str(ng))


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

Submission status: Wrong Answer

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

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

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

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

print(mid)

Submission status: Wrong Answer

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

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

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

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

print(mid)

Submission status: Wrong Answer

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

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

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

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

print(mid)

Submission status: Wrong Answer

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


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    
    a = -1
    b = 2*10**17 + 1

    x = max(sum(A) - K, 0)
    # print("x", x)

    while(a+1 < b):
        c = (a+b)//2
        d = sum(c//f for f in F)

        # print(c, d)

        if d >= x:
            b = c
        else:
            a = c

    print(b)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

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

print(mid)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = [int(_) for _ in input().split()]
f = [int(_) for _ in input().split()]
a.sort()
f.sort(key=lambda x:-x)

INF = 1<<60

def C(x):
    tmp = 0
    for i in range(N):
        tmp += max(0,a[i]-x//f[i])
    if tmp<=K:
        return True
    else:
        return False

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

print(mid)

Submission status: Wrong Answer

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

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


    max_ = 10**12
    min_ = 0

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

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


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N,K = int(N),int(K)
A = np.array([int(a) for a in A])
F = np.array(sorted([int(f) for f in F]))[::-1]

for i in range(K):

    mal_list = np.sort(A)*F
        
    ind = np.argmax(mal_list)
    
    if(A[ind]>0):
        A[ind] -= 1
        A = np.sort(A)
    else:
        break
    #print(A)

mal_list = np.max(A*F)
print(np.max(mal_list),A)

Submission status: Wrong Answer

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

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

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

    print(ok)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

if sum(A) <= K:
    x = 0
else:
    u = 10**12
    l = 0
    while u-l > 1:
        x = (u+l)//2
        k = 0
        for i in range(N):
            k += A[i] - x//F[i]
        if k < K:
            u = x
        elif k == K:
            u = l
        else:
            l = x
    x = (u+l)//2
    k = 0
    for i in range(N):
        k += A[i] - (x-1)//F[i]
    if K >= k:
        x -= 1
    k = 0
    for i in range(N):
        k += A[i] - x//F[i]
    if K < k:
        x += 1
    
print(x)

Submission status: Wrong Answer

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

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

if sum(A) <= K:
    x = 0
else:
    u = 10**12
    l = 0
    while u-l > 1:
        x = (u+l)//2
        k = 0
        for i in range(N):
            k += A[i] - x//F[i]
        if k < K:
            u = x
        elif k == K:
            u = l
        else:
            l = x
    k = 0
    for i in range(N):
        k += A[i] - (x-1)//F[i]
    if K >= k:
        x -= 1
    k = 0
    for i in range(N):
        k += A[i] - x//F[i]
    if K < k:
        x += 1
    
print(x)

Submission status: Wrong Answer

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

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

if sum(A) <= K:
    x = 0
else:
    u = 10**12
    l = 0
    while u-l > 1:
        x = (u+l)//2
        k = 0
        for i in range(N):
            k += A[i] - x//F[i]
        if k < K:
            u = x
        elif k == K:
            u = l
        else:
            l = x
    
    for i in range(N):
        K -= A[i] - (x-1)//F[i]
    if K >= 0:
        x -= 1
print(x)

Submission status: Wrong Answer

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

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

if sum(A) <= K:
    x = 0
else:
    u = 10**12
    l = 0
    while u-l > 1:
        x = (u+l)//2
        k = 0
        for i in range(N):
            k += A[i] - x//F[i]
        if k < K:
            u = x
        elif k == K:
            u = l
        else:
            l = x
        

print(x)

Submission status: Wrong Answer

Solution code:
def binary_search(a, f, target, left, right):
    ans = a[-1] * f[-1]
    while left + 1 < right:
        mid = (left+right)//2
        cost = 0
        for aa,ff in zip(a,f):
            if aa - mid // ff > 0:
                cost += aa - mid // ff
        if cost > target:
            left = mid
        else:
            right = mid
    return right

n,k = map(int,input().split())
a = sorted(map(int, input().split()), reverse=True)
f = sorted(map(int, input().split()))
target = binary_search(a,f,k,0,max(a) * max(f))
mx = 0
cost = 0
for aa, ff in zip(a,f):
    if aa - target // ff > 0:
        aa = (target // ff)
        cost += aa - target // ff
    if mx < aa * ff:
        mx = aa * ff
print(mx)

Submission status: Wrong Answer

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

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


    max_ = 10**12
    min_ = 0

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

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


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









if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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


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

Submission status: Wrong Answer

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

def judge(a, f, k):
    return (a*f-k-1)//f+1

low, high = 0, 10**12+1
while low < high-1:
    key = (low+high)//2
    value = 0
    for i in range(n):
        value += judge(a[i], f[i], key)
    if value == k:
        print(key)
        sys.exit()
    if value < k:
        high = key
    else:
        low = key

value = 0
for i in range(n):
    value += judge(a[i], f[i], low)
if value <= k:
    print(low)
else:
    print(high)