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 sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索
N, K = lr()
A = np.array(lr())
F = np.array(lr())
A.sort()
F = np.sort(F)[::-1]

def check(x):
    count = (A - (x // F)).sum()
    return count <= K

if A.sum() <= K:
    print(0)
    exit()

left = 10 ** 12 # 可能
right = 0 # 不可能
while left > right + 1:
    mid = (left+right) // 2
    if check(mid):
        left = mid
    else:
        right = mid

print(left)
# 51

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索
N, K = lr()
A = np.array(lr())
F = np.array(lr())
A.sort()
F = np.sort(F)[::-1]

def check(x):
    count = (A - (x // F)).sum()
    return count <= K

left = 10 ** 12 # 可能
right = -1 # 不可能
while left > right + 1:
    mid = (left+right) // 2
    if check(mid):
        left = mid
    else:
        right = mid

print(left)
# 51

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索
N, K = lr()
A = np.array(lr())
F = np.array(lr())
A.sort()
F = np.sort(F)[::-1]

def check(x):
    count = (A - (x // F)).sum()
    return count <= K

left = 10 ** 12 # 可能
right = -1 # 不可能
while left > right + 1:
    mid = (left+right) // 2
    if check(mid):
        left = mid
    else:
        right = mid

print(left)
# 51

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索
N, K = lr()
A = np.array(lr())
F = np.array(lr())
A.sort()
F = np.sort(F)[::-1]

def check(x):
    count = (A - (x // F)).sum()
    return count <= K

left = 10 ** 12 # 可能
right = 0 # 不可能
while left > right + 1:
    mid = (left+right) // 2
    if check(mid):
        left = mid
    else:
        right = mid

print(left)
# 51

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

def isok(a,f,n,k,m):
    a.sort()
    aa = m // f
    aa.sort()
    s = 0
    for i in range(n):
        s += max(0,a[i] - aa[i])
    if s > k:
        return False
    else:
        return True

mini = -1
maxi = a[-1] * f[-1]
while maxi - mini > 1:
    mid = mini + (maxi - mini) // 2
    if isok(a,f,n,k,mid):
        maxi = mid
    else:
        mini = mid

print(maxi)

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

def isok(a,f,n,k,m):
    a.sort()
    aa = m // f
    f.sort()
    aa.sort()
    s = sum(a - aa)
    if s > k:
        return False
    else:
        return True

mini = -1
maxi = max(a) * max(f)
while maxi - mini > 1:
    mid = mini + (maxi - mini) // 2
    if isok(a,f,n,k,mid):
        maxi = mid
    else:
        mini = mid

print(maxi)

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

def isok(a,f,n,k,m):
    a.sort()
    aa = m // a
    f.sort()
    aa.sort()
    s = sum(a - aa)
    if s > k:
        return False
    else:
        return True

mini = -1
maxi = max(a) * max(f)
while maxi - mini > 1:
    mid = mini + (maxi - mini) // 2
    if isok(a,f,n,k,mid):
        maxi = mid
    else:
        mini = mid

print(maxi)

Submission status: Wrong Answer

Solution code:
def solve():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    F = list(map(int,input().split()))
    A.sort()
    F.sort(reverse=True)
    i = 0
    # print(A,F)
    # print([A[i]*F[i] for i in range(N)], sum([A[i]*F[i] for i in range(N)]))
    AF = [A[i]*F[i] for i in range(N)]
    left = 0
    right = max(AF)
    ret = (right+left)//2
    while right-left > 1:
        # check
        check_k = K
        # print(ret, left,right)
        flag = True
        for i,af in enumerate(AF):
            if af > ret:
                req = ((af-ret)//F[i])+1
                if check_k >= req:
                    check_k -= req
                else:
                    flag = False
                    break
        
        if not flag:
            # print('ng')
            left = ret
        else:
            # print('ok')
            right = ret
        
        ret = (right+left)//2
        # print(left,right)
    
    
    print(left)
    
solve()

Submission status: Wrong Answer

Solution code:
from math import ceil

def check(N_:int,S_:list,F_:list,upper:int,K_:int)->bool:
    #A_i > A_j (i < j)
    cnt = 0
    for i in range(N_):
        s = S_[i]
        if s > upper:
            cnt += ceil((s - upper)/F_[i])
            if cnt > K_:
                return False
        else:
            return True
    return True


def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    F = list(map(int,input().split()))
    A.sort(reverse = True)
    F.sort()
    S = [f*a for f,a in zip(F,A)]
    right = sum(S)
    left = -1
    while left + 1 < right:
        mid = (right + left) // 2
        if mid == right:
            break
        if check(N,S,F,mid,K):
            right = mid
        else:
            left = mid
    print(right)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil

def check(N_:int,S_:list,F_:list,upper:int,K_:int)->bool:
    #A_i > A_j (i < j)
    cnt = 0
    for i in range(N_):
        s = S_[i]
        if s > upper:
            cnt += ceil((s - upper)/F_[i])
            if cnt > K_:
                return False
        else:
            return True
    return True


def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    F = list(map(int,input().split()))
    A.sort(reverse = True)
    F.sort()
    S = [f*a for f,a in zip(F,A)]
    right = sum(S)
    left = -1
    while left + 1 < right:
        mid = (right + left) // 2
        if mid == right:
            break
        if check(N,S,F,mid,K):
            right = mid
        else:
            left = mid + 1
    print(mid)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N , K = map(int,input().split())
A = np.array(sorted(list(map(int,input().split()))))
B = np.array(sorted(list(map(int,input().split())) , reverse = True))
M = A * B
if sum(B)<K:
  print(0)
  sys.exit()
def is_ok(n):
    print(n)
    cnt = 0
    for i in range(N):
        if M[i]>n:
            cnt += B[i] - (n)//A[i]
    if cnt > K:
        return False
    else :
        return True
ok = max(M)
ng = 0
while ok-ng > 1:
    mid = (ok+ng) // 2 # 平均(小数切り捨て)
    if is_ok(mid) :
        ok = mid
    else :
    	ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N , K = map(int,input().split())
A = np.array(sorted(list(map(int,input().split()))))
B = np.array(sorted(list(map(int,input().split())) , reverse = True))
M = A * B
if sum(B)<K:
  print(0)
  sys.exit()
def is_ok(n):
    cnt = 0
    for i in range(N):
        if M[i]>n:
            cnt += B[i] - n//A[i] 
    if cnt > K:
        return False
    else :
        return True
ok = max(M)
ng = 0
while ok-ng > 1:
    mid = (ok+ng) // 2 # 平均(小数切り捨て)
    if is_ok(mid):
        ok = mid
    else:
    	ng = mid
print(ok)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

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 func(x):
        count = 0
        for co,ha in zip(a,f):
            tr = x//ha
            if co <= tr:
                continue
            count += co-tr
        if K <= count:
            return True
        else:
            return False
    l,r = -1,a[-1]*f[0]+1
    while r-l > 1:
        mid = (l+r)//2
        if func(mid):
            l = mid
        else:
            r = mid
            
    print(r)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

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 func(x):
        count = 0
        for co,ha in zip(a,f):
            tr = mid//ha
            if co <= tr:
                continue
            count += co-tr
        if K <= count:
            return True
        else:
            return False
    l,r = -1,a[-1]*f[0]+1
    while r-l > 1:
        mid = (l+r)//2
        if func(mid):
            l = mid
        else:
            r = mid
            
    print(r)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

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)
    l,r = -1,10**20
    while r-l > 1:
        mid = (l+r)//2
        count = 0
        for i in range(N):
            tr = a[i] - mid//f[i]
            count += tr
        if K < count:
            l = mid
        else:
            r = mid
            
    print(r)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def f(x):
    ans = 0
    for i,j in zip(A, F):
        ans += (i*j-x+j-1)//j if i*j-x>=0 else 0
    return ans<=K

l, r = 0, 10**18+1
while r-l>1:
    mid = l+(r-l)//2
    if f(mid):
        r = mid
    else:
        l = mid

print(r)

Submission status: Wrong Answer

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

def f(x):
    ans = 0
    for i,j in zip(A, F):
        ans += (i*j-x+j-1)//j if i*j-x>=0 else 0
    return ans<=K

l, r = 0, 10**18
while r-l>1:
    mid = (l+r)//2
    if f(mid):
        r = mid
    else:
        l = mid

print(r)

Submission status: Wrong Answer

Solution code:
import numpy as np


def main():
    N, K = [int(x) for x in input().split()]
    A = [float(x) for x in input().split()]
    F = [float(x) for x in input().split()]

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

    min_time = 0
    max_time = A[-1] * F[0]

    while max_time != min_time:
        tgt_time = (min_time + max_time)//2
        ideal_a = np.floor(tgt_time*np.ones(N)/F)
        require_k = np.sum(A - ideal_a)
        if require_k <= K:
            max_time = tgt_time
        else:
            min_time = tgt_time+1

    print(int(max_time))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
f_list = list(map(int, input().split()))

# もし修行により消化コストが全て0になる場合
if sum(a_list) <= k:
    print(0)
    exit()

# 更新メソッド
def update_cost():
    min_cost = []
    for i in range(len(a_list)):
        min_cost.append(a_list[i] * f_list[i])
    return min_cost

# ソート
a_list.sort()
f_list.sort(reverse=True)

# コストリストinit
min_cost = update_cost()

# 修行する
while k > 0:
    # 現状で最もコストが大きいものについて考える
    max_idx = min_cost.index(max(min_cost))

    # 修行実行
    a_list[max_idx] -= 1
    a_list.sort()

    # コストリスト更新
    update_cost()

    # 修行数減らす
    k -= 1

Submission status: Wrong Answer

Solution code:
def ok_(n):
    #print("########### ok_  n:",n)
    global A,F,S,N,K
    k = K
    for i in range(N):
        a,f,s = A[i], F[i], S[i]
        #print(n,a,f,s)
        if n < s:
            #print("#=#",(s-n-1)//f + 1)
            k -= (s-n-1)//f + 1
    #print("res ########",k)
    if k < 0:
        return False
    else:
        return True

N,K = [int(i) for i in input().rstrip().split(' ')]
A = [int(i) for i in input().rstrip().split(' ')]
F = [int(i) for i in input().rstrip().split(' ')]
A.sort()
F.sort(reverse=True)
S = [A[i]*F[i] for i in range(N)]
ok = max(S)
ng = 0
while ok - ng > 1:
    m = (ok + ng + 1) // 2
    if ok_(m):
        ok = m
    else:
        ng = m
    #print(ng,m,ok)
print(ok)

Submission status: Wrong Answer

Solution code:
def ok_(n):
    global A,F,S,N,K
    k = K
    for i in range(N):
        a,f,s = A[i], F[i], S[i]
        if n < s:
            k -= (s-n)//f + 1
    if k < 0:
        return False
    else:
        return True

N,K = [int(i) for i in input().rstrip().split(' ')]
A = [int(i) for i in input().rstrip().split(' ')]
F = [int(i) for i in input().rstrip().split(' ')]
A.sort()
F.sort(reverse=True)
S = [A[i]*F[i] for i in range(N)]
ok = max(S)
ng = 0
while ok - ng > 1:
    m = (ok + ng + 1) // 2
    if ok_(m):
        ok = m
    else:
        ng = m
    #print(ng,m,ok)
print(ng)

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

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

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

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

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



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

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
def main(x):
    _K=K
    for i in range(N):
        _K-=A[i]-x//F[i]
        if _K<0:
            return(0)
    return(1)


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

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

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

Submission status: Wrong Answer

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]
mul = A*F
if K >= sum(A)*N:
    print(0)
    exit()

ma = 2**20
mi = 0
while 1:
    tgt = (ma + mi)//2
    num = 0
    for m,f in zip(mul,F):
        tmp = np.ceil((m-tgt)/f)
        if tmp < 0:
            tmp = 0
        num += tmp
    if ma == mi:
        print(ma)
        exit()
    if num <= K:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2+1

Submission status: Wrong Answer

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


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

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

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

Submission status: Wrong Answer

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


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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math

input=sys.stdin.readline

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

a=sorted(a,reverse=True)
b=sorted(b)

def ok(N):
    sums=0
    for i in range(n):
        sums+=max(0,a[i]-N//b[i])
    if sums<=k:
        return True
    else:
        return False
    


left=0
right=10**6

for _ in range(30):
    if ok(math.floor((left+right)/2)):
      left=left
      right=(left+right)/2
    elif not ok(math.floor((left+right)/2)):
      left=(left+right)/2
      right=right
print(math.floor(right))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
F.sort()
suma = sum(A)
u = 10**12
d = 0
for i in range(50):
    x = (u + d)//2
    s = 0
    for i in range(N):
        f = F[i]
        s += x//f
    if suma - s <= K:
        u = x
    else:
        d = x
print(u)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    F = list(map(int,input().split()))
    if sum(A) <= K:
        print(0)

    else:
        A.sort()
        F.sort(reverse=True)
        
        left = 0
        right = 10**18
        while right - left != 1:
            score = (left+right)//2
            training = 0
            for i in range(N):
                cost,diff = A[i],F[i]
                t = -(-(cost*diff-score)//diff)
                training += t
            if training <= K:
                right = score
            else:
                left = score
        print(right)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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

Submission status: 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=-1
r=10**13
while r-l!=1:
    m=(l+r)//2
    x=0
    for i in range(N):
        x+=A[i]-m//F[i]
    if x<=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()
f.reverse()

for i in range(n):
    if a[i]>=k:
        a[i]-=k
        break
    else:
        k-=a[i]
        a[i]=0

ans = 0
for i in range(n):
    ans += a[i]*f[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(sorted(list(map(int,input().split())),reverse=True))
f = list(sorted(list(map(int,input().split()))))
ta = max(0,sum(a)-k)
if ta==0:print(0)
else:
    sm = 0
    smlist = [0] * n
    for j,fi in enumerate(f):
        smlist[j] = f[-1]/fi
        sm += f[-1]/fi
    t = ta/sm
    for i in range(n):
        smlist[i] *= t 
    intsmlist = [0] * n
    for i in range(n):
        temp = smlist[i]
        itemp = int(temp)
        if temp != int(temp):
            itemp += 1
        intsmlist[i] = itemp 
    newa = []
    newf = []
    for i in range(n):
        if a[i] < intsmlist[i]:
            pass
        else:
            newa.append(a[i])
            newf.append(f[i])

    newta = max(0,sum(newa)-k)
    if newta==0:print(0)
    else:
        newn = len(newa)
        sm2 = 0
        smlist2 = [0] * newn
        for j,fi in enumerate(newf):
            smlist2[j] = newf[-1]/fi
            sm2 += newf[-1]/fi
        t2 = newta/sm2
        for i in range(newn):
            smlist2[i] *= t2 
        intsmlist2 = [0] * newn
        for i in range(newn):
            temp = smlist2[i]
            itemp = int(temp)
            if temp != int(temp):
                itemp += 1
            intsmlist2[i] = itemp
        newdif= sum(intsmlist2) - newta
        newans = []
        for bb,ff in zip(intsmlist2,f):newans.append(bb*ff)
        newans.sort(reverse=True)
        print(newans[newdif])

Submission status: Wrong Answer

Solution code:
import numpy as np
def calc(s, th, f):
    p = np.maximum(s-th, 0)
    w = (p + f - 1) // f
    cost = np.sum(w)
    return cost

def solve(n, k, a, f):
    a = sorted(a)
    f = sorted(f)[::-1]
    a = np.asarray(a, dtype=int)
    f = np.asarray(f, dtype=int)
    s = a * f
    l = 0
    r = np.max(s)
    while r - l > 1:
        th = (l + r) // 2
        cost = calc(s, th, f)
        if cost < k:
            r = th
        elif cost > k:
            l = th
        else:
            l = th
            r = th
            break
    return r if (k < calc(s, l, f)) else l

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

Submission status: Wrong Answer

Solution code:
import numpy as np
def calc(s, th, f):
    w = np.ceil(np.maximum((s - th), 0) / f).astype(int)
    cost = np.sum(w)
    return cost

def solve(n, k, a, f):
    a = sorted(a)
    f = sorted(f)[::-1]
    a = np.asarray(a, dtype=int)
    f = np.asarray(f, dtype=int)
    s = a * f
    l = 0
    r = np.max(s)
    for i in range(100):
        th = (l + r) // 2
        cost = calc(s, th, f)
        if cost < k:
            r = th
        elif cost > k:
            l = th
        else:
            l = th
            r = th
            break
    return r if (k < calc(s, l, f)) else l

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

Submission status: Wrong Answer

Solution code:
import numpy as np
def calc(s, th, f):
    w = np.ceil(np.maximum((s - th), 0) / f).astype(int)
    cost = np.sum(w)
    return cost

def solve(n, k, a, f):
    a = sorted(a)
    f = sorted(f)[::-1]
    a = np.asarray(a, dtype=int)
    f = np.asarray(f, dtype=int)
    s = a * f
    l = 0
    r = np.max(s)
    for i in range(100):
        th = (l + r) // 2
        cost = calc(s, th, f)
        if (l == th) or (r == th):
            break
        elif cost < k:
            r = th
        elif cost > k:
            l = th
        else:
            l = th
            r = th
            break
    return r if (k < calc(s, l, f)) else l

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
N,K=map(int,input().split())
A=np.array([int(i) for i in input().split()])
F=np.array([int(i) for i in 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

l=0
r=A[-1]*F[-1]*N**2
while r-l > 1:
    #print(l,r)
    m = (l+r)//2
    if test(m):
        r=m
    else:
        l=m
if test(l):
    print(l)
else:
    print(l+1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
N,K=map(int,input().split())
A=np.array([int(i) for i in input().split()])
F=np.array([int(i) for i in 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

l=0
r=A[-1]*F[-1]*N
while r-l > 1:
    #print(l,r)
    m = (l+r)//2
    if test(m):
        r=m
    else:
        l=m
if test(l):
    print(l)
else:
    print(l+1)