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: Time Limit Exceeded

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, k = mi()
    A = sorted(lmi(), reverse=True)
    F = sorted(lmi())
    h = [[- A[i] * F[i], F[i]] for i in range(n)]
    heapify(h)
    # print(h)
    for _ in range(k):
        minus_val, cost = heappop(h)
        plus_val = - minus_val
        # plus_val は max heap から取り出した最大値となる
        if plus_val == 0:
            # もう減らす場所はない。一応戻して抜ける
            heappush(h, [plus_val, cost])
            break
        plus_val -= cost
        heappush(h, [- plus_val, cost])
    
    minus_val, cost = heappop(h)
    print(- minus_val)    



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for train in range(k):
    a.sort()
    f.sort()
    af = []
    '''
    print('a = {}'.format(a))
    print('f = {}'.format(f))
    '''
    for i in range(n):
        af.append(a[n-i-1]*f[i])

    maxindex = af.index(max(af))
    if a[n-maxindex-1] >= 1:
        a[n-maxindex-1] -= 1

a.sort()
f.sort()
af = []
for i in range(n):
    af.append(a[n-i-1]*f[i])
print(max(af))

Submission status: Time Limit Exceeded

Solution code:
def f(point):
    k = K
    for i in range(N):
        a = A[i]
        f = F[i]
        if a*f > point:
            k -= a - point//f
        if k < 0:
            return False
    return True

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+1
while (r-l) > 1:
    mid = (r+l)//2
    if f(mid):
        r = mid
    else:
        l = mid
print(r)

Submission status: Time Limit Exceeded

Solution code:
def f(point):
    k = K
    for i in range(N):
        a = A[i]
        f = F[i]
        if a*f > point:
            k -= a - point//f
        if k < 0:
            return False
    # print(point, k)
    return True

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**18+1
while (r-l) > 1:
    mid = (r+l)//2
    if f(mid):
        r = mid
    else:
        l = mid
print(r)

Submission status: Time Limit Exceeded

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)
costs = [(ai * fi, fi) for ai, fi in zip(a, f)]
costs.sort(reverse=True)
# l impossible, r ok
l, r = -1, costs[0][0]
while(r - l > 1):
    c = (l + r) // 2
    train = 0
    for cost, step in costs:
        if cost > c:
            train += (cost - c + step - 1) // step
    if train <= k:
        r = c
    else:
        l = c
print(r)

Submission status: Time Limit Exceeded

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

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    f = list(map(int, input().split()))
    a = sorted(a)
    f = sorted(f)
    f = f[::-1]
    mi = -1  # Impossible
    ma = 10 ** 12  # Possible
    for i in range(100):
        md = mi + (ma - mi) // 2
        if can_achieve(md, a, f, k, n):
            ma = md
        else:
            mi = md
        if ma - mi <= 1:
            break
    print(ma)

def can_achieve(score, a, f, k, n):
    sumb = 0
    for i in range(n):
        b = a[i] - score // f[i]
        b = max(b, 0)
        sumb += b
    return k >= sumb

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
A=sorted(list(map(int,input().split())))
F=sorted(list(map(int,input().split())),reverse=True)
ng=-1
ok=10**12+10
while ok-ng>1:
  mid=(ok+ng)//2
  a=0
  for i in range(n):
    a=a+max(0,A[i]-mid//F[i])
  if a>k:
    ng=mid
  else:
    ok=mid
print(ok)

Submission status: Time Limit Exceeded

Solution code:
# わからんだろこれ 降順ソート*昇順ソートからの発想が浮かばず
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = -1, 10**12 + 1  # ちゃんと「取りうることがないもののうち最大値」「取りうることのない最小値」でやる.....

while r - l > 1:
    mid = (r + l) // 2  # 最大値これをめざす
    cur = 0
    for i in range(n):
        if a[i] * b[i] <= mid:
            # Kを使う必要がない
            pass
        else:
            # Kからどんくらい使うか これむずくない？
            cur += a[i] - mid // b[i]
        if cur > k:
            l = mid
            break
        # cur += max(0, a[i] - mid // b[i])
        # if cur > k:
        #     break
    if cur > k:
        l = mid
    else:
        r = mid
print(r)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip('\n')

##### main

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)
AxF = [A[i]*F[i] for i in range(N)]
AxFmax = max(AxF)

def is_possible(x):
    _sum = 0
    for i in range(N):
        _sum += max(0, A[i] - x//F[i])
    #print(x,_sum,K)
    return _sum <= K

left = 0
right = AxFmax

while(left != right):
    x = (left+right)//2
    if is_possible(x):
        right = x
    else:
        left = x+1
    #print('main', left, right, x)
            
print(left)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import math
    import sys
    input = sys.stdin.readline

    n,k = map(int,input().split())
    a = sorted(list(map(int,input().split())))
    f = sorted(list(map(int,input().split())),reverse=True)
    check = []
    for i in range(n):
        check.append((a[i]*f[i],a[i],f[i]))

    def search(x):
        count = 0

        for i,j,k in check:
            if i > x:
                y = math.floor(x/k)
                count += j-y
        return count

    left = -1
    right = 10**12+2
    while right > left+1:
        mid = (right+left)//2
        if search(mid) > k:
            left = mid
        else:
            right = mid
    print(right)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
f = sorted(list(map(int,input().split())),reverse=True)
check = []
for i in range(n):
    check.append((a[i]*f[i],a[i],f[i]))

def search(x):
    count = 0

    for i,j,k in check:
        if i > x:
            y = math.floor(x/k)
            count += j-y
    return count

left = -1
right = 10**13
while right > left+1:
    mid = (right+left)//2
    if search(mid) > k:
        left = mid
    else:
        right = mid
print(right)

Submission status: Time Limit Exceeded

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)
z=[]
##print(a)
##print(f)
for i in range(n):
  z.append(a[i]*f[i])
#temp=
for i in range(k):
  q=z.index(max(z))
  ##print(z)
  z[q]-=f[q]
print(max(z))

Submission status: Time Limit Exceeded

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

def solve(x):
    lk = k
    for i, j in zip(a, f):
        if i*j<=x:
            continue
        lk -= (j*(i+1)-x-1)//j
        if lk<0:
            return False
    return True

ok = 10**12
ng = -1
while abs(ok-ng)>1:
    mid = (ok+ng)//2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())))[::-1]
s=[0]*n
for i in range(n):
  s[i]=a[i]*f[i]

for i in range(k):
  xv=max(s)
  x=s.index(xv)
  s[x]-=f[x]

if k>sum(a):
  s=[0]*n
print(max(s))

Submission status: Time Limit Exceeded

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, 10**18
if sum(A)<=k:
    print(0)
else:
    while r-l!=1:
        mid = (r+l)//2
        ex = 0
        for i in range(n):
            need = mid // F[i]
            ex += max(0, A[i]-need)
        if ex <= k:
            r = mid
        else:
            l = mid
    print(r)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()), reverse=True)
t = [a[i] * f[i] for i in range(n)]

inf = -1 #NG
sup = 10 ** 12 #OK

while sup - inf > 1:
  x = (inf + sup) // 2
  train = 0
  for i in range(n):
    train += max(t[i] - x - 1, -1) // f[i] + 1
  if train <= k:
    sup = x
  else:
    inf = x
    
print(sup)

Submission status: Time Limit Exceeded

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


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


left = -1
right = 10 ** 12 + 1

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

print(right)

Submission status: Time Limit Exceeded

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

def solve(N, K, a, f, num):
    cost = 0
    for i in range(N):
        cost += max(0, a[i] - (num//f[i]))
        if cost > K:
            return False
    return True


def main():
    N, K = map(int, input().split())
    a = sorted(list(map(int, input().split())))
    f = sorted(list(map(int, input().split())), reverse=True)

    l, r = 0, int(1e12)
    while l != r:
        # print(l, r)
        p = (l + r) // 2
        tmp = solve(N, K, a, f, p)
        # print(l, p, r, tmp)
        if tmp:
            r = p
        else:
            l = p + 1
        # break
    
    print(l)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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)
maxi = 0
while(k>0):
    for i in range(n):
        if A[i]*F[i]>maxi:
            maxi = A[i]*F[i]
            t_i = i
    A[t_i]-=1
    k-=1
    if maxi<0:break
    maxi=0
for i in range(n):
    if A[i]*F[i]>maxi:
        maxi = A[i]*F[i]
print(maxi)

Submission status: Time Limit Exceeded

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

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

def condition(num):
    count=0
    goal=[num//F[i] for i in range(N)]
    for i in range(0,N):
        if A[i]>goal[i]:
            count+=A[i]-goal[i]
    return K>=count

start=0
end=10**20
while end-start>1:
    test=(end+start)//2
    if condition(test):
        end=test
    else:
        start=test

if condition(start):
    print(start)
else:
    print(end)

Submission status: Time Limit Exceeded

Solution code:
#144_E
n, k = map(int, input().split())
a = sorted(list(map(int,input().split())))
f = sorted(list(map(int,input().split())))[::-1]

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

Submission status: Time Limit Exceeded

Solution code:
#144_E
import heapq
n, k = map(int, input().split())
a = sorted(list(map(int,input().split())))
f = sorted(list(map(int,input().split())))[::-1]

cost = [(-a[i]*f[i], i) for i in range(n)]
heapq.heapify(cost)
for _ in range(k):
    x, idx = heapq.heappop(cost)
    if x == 0:
        break
    heapq.heappush(cost, (-(-x // f[idx] - 1) * f[idx], idx))
print(-heapq.heappop(cost)[0])

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
Minus_A = [-x for x in A]
F = sorted(F, reverse=True)

high = 10**12
low = 0
while high - low > 1:
    mid = low + (high-low)//2
    count = 0

    for i in range(n):
        now = mid // F[i]
        count += max(A[i] - now, 0)
    
    # print('-'*30)
    # print(mid)
    # print(count)
    if count > k:
        low = mid
    else:
        high = mid
    
ans = high

if sum(A) <= k:
    ans = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

A = sorted(A)
Minus_A = [-x for x in A]
F = sorted(F, reverse=True)

Sec = []
for i in range(n):
    Sec.append(Minus_A[i]*F[i])

hq = []
for i in range(n):
    heapq.heappush(hq, [Sec[i], Minus_A[i], F[i]])

for i in range(k):
    dec_obj = heapq.heappop(hq)
    if dec_obj[1] < 0:
        dec_obj[1] = dec_obj[1] + 1
        dec_obj[0] = dec_obj[1] * dec_obj[2]
        heapq.heappush(hq, dec_obj)
        # print(hq)
    else:
        break

ans_obj = heapq.heappop(hq)
ans = ans_obj[0] * -1
print(ans)

Submission status: Time Limit Exceeded

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

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

left = 0
right = 10**12
while True:
    mid = (left+right)//2
    if right - left <= 1:
        count = 0
        for i in range(N):
            a = left//F[i]
            count+=max(0,A[i]-a)
        if count <= K:
            ans = left
        else:
            ans = right
        break
    
    
    count = 0
    for i in range(N):
        a = mid//F[i]
        count+=max(0,A[i]-a)
    #print(right,left,count)
    if count <= K:
        right = mid
    else:
        left = mid
        
        

print(ans)

Submission status: Time Limit Exceeded

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()
ng=-1
ok=10**12
while ok-ng>1:
    mid=(ok+ng)//2
    temp=0
    flag=0
    for i in range(n):
        a=mid//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        ng=mid
    else:
        ok=mid

print(ok)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    import numpy as np

    n,k=map(int,input().split())
    A=np.array(input().split(),dtype=np.int64)
    F=np.array(input().split(),dtype=np.int64)
    A.sort()
    F.sort()
    F=F[::-1]

    def ok(x): #チームの成績をxとするような修行の仕方が存在するか
        B=A-(x//F)
        return sum(B[B>0])<=k
    
    l=-1
    r=10**12+1
    while r-l>1:
        mid=(r+l)//2
        if ok(mid):
            r=mid
        else:
            l=mid
    print(r)   

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read=sys.stdin.buffer.read
import numpy as np

n,k=map(int,input().split())
A=np.array(input().split(),np.int64)
F=np.array(input().split(),np.int64)
A.sort()
F.sort()
F=F[::-1]
    
def ok(x): #チームの成績をxとするような修行の仕方が存在するか
    B=A-x//F
    return sum(B[B>0])<=k
    
l=-1
r=10**18
while r-l>1:
    mid=(r+l)//2
    if ok(mid):
        r=mid
    else:
        l=mid
print(r)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
import numpy as np

def main():
    n,k=map(int,input().split())
    A=np.array(input().split(),np.int64)
    F=np.array(input().split(),np.int64)
    A.sort()
    F.sort()
    F=F[::-1]

    def ok(x): #チームの成績をxとするような修行の仕方が存在するか
        B=A-(x//F)
        return sum(B[B>0])<=k
    
    l=-1
    r=10**18
    while r-l>1:
        mid=(r+l)//2
        if ok(mid):
            r=mid
        else:
            l=mid
    print(r)   

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    import numpy as np

    n,k=map(int,input().split())
    A=np.array(input().split(),np.int64)
    F=np.array(input().split(),np.int64)
    A.sort()
    F.sort()
    F=F[::-1]

    def ok(x): #チームの成績をxとするような修行の仕方が存在するか
        B=A-(x//F)
        return sum(B[B>0])<=k
    
    l=-1
    r=10**18
    while r-l>1:
        mid=(r+l)//2
        if ok(mid):
            r=mid
        else:
            l=mid
    print(r)   

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    import numpy as np

    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    A.sort()
    F.sort(reverse=True)
    A=np.array(A)
    F=np.array(F)
    
    def ok(x): #チームの成績をxとするような修行の仕方が存在するか
        B=A-(x//F)
        return sum(B[B>0])<=k
    
    l=-1
    r=10**18
    while r-l>1:
        mid=(r+l)//2
        if ok(mid):
            r=mid
        else:
            l=mid
    print(r)   

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.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)
    r = A[-1]*F[0]
    l = -1
    while(r-l > 1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            if x*y > tmp:
                k += x - (tmp // y)
            #k += max(0, x - (tmp // y))
        if K >= k:
            r = tmp
        else:
            l = tmp
    print(r)
main()

Submission status: Time Limit Exceeded

Solution code:
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)
    r = A[-1]*F[0]
    l = -1
    while(r-l > 1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            if x*y > tmp:
                k += x - (tmp // y)
            #k += max(0, x - (tmp // y))
        if K >= k:
            r = tmp
        else:
            l = tmp
    print(r)
main()

Submission status: Time Limit Exceeded

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 = A[-1]*F[0]
l = -1
while(r-l > 1):
    tmp = (l+r)//2
    k = 0
    for x, y in zip(A, F):
        if x*y > tmp:
            k += x - (tmp // y)
        #k += max(0, x - (tmp // y))
    if K >= k:
        r = tmp
    else:
        l = tmp
print(r)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
def check(tmp):
    k = 0
    for x, y in zip(A, F):
        if x*y > tmp:
            k += x - (tmp // y)
        #k += max(0, x - (tmp // y))
    return(K >= k)
A.sort()
F.sort(reverse=True)
r = A[-1]*F[0]
l = -1
while(r-l > 1):
    tmp = (l+r)//2
    if check(tmp):
        r = tmp
    else:
        l = tmp
print(r)

Submission status: Time Limit Exceeded

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


def check(tmp):
    k = 0
    for x, y in zip(A, F):
        t = tmp // y
        if x > t:
            k += x - t
        #k += max(0, x - (tmp // y))
    return(K >= k)


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

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

while(r-l > 1):
    tmp = (l+r)//2
    if check(tmp):
        r = tmp
    else:
        l = tmp
print(r)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
def check(tmp):
    k = 0
    for x, y in zip(A, F):
        k += max(0, x - (tmp // y))
    return(K >= k)
A.sort()
F.sort(reverse=True)

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

while(r-l > 1):
    tmp = (l+r)//2
    if check(tmp):
        r = tmp
    else:
        l = tmp
print(r)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.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)

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

    l = -1

    while(r-l > 1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            k += max(0, x - (tmp // y))
        if k > K:
            l = tmp
        else:
            r = tmp
    print(r)


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
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 = A[-1]*F[0]

l = -1

while(r-l > 1):
    tmp = (l+r)//2
    k = 0
    for x, y in zip(A, F):
        k += max(0, x - (tmp // y))
    if k > K:
        l = tmp
    else:
        r = tmp
print(r)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import sys
input = sys.stdin.readline
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 = A[-1]*F[0]

l = -1

while(r-l > 1):
    tmp = (l+r)//2
    k = 0
    for x, y in zip(A, F):
        k += max(0, x - (tmp // y))
    if k > K:
        l = tmp
    else:
        r = tmp
print(r)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
S = sum(A)
if S <= K:
    print(0)

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

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

    l = 0

    while(r-l > 1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            k += max(0, x - (tmp // y))
        if k > K:
            l = tmp
        else:
            r = tmp
    print(r)

Submission status: Time Limit Exceeded

Solution code:
import heapq
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
S = sum(A)
if S <= K:
    print(0)

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

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

    l = 0

    while(1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            k += max(0, x - (tmp // y))
        if k > K:
            l = tmp
        else:
            r = tmp

        if l+1 == r:
            print(r)
            exit(0)

Submission status: Time Limit Exceeded

Solution code:
def sub(x):
	global A;	global F;	global K
	s = 0
	for i in range(N):
		s += max(A[i] - x // F[i], 0)
	return s <= K

N, K = map(int,input().split())
A = list(map(int,input().split())); A.sort()
F = list(map(int,input().split())); F.sort(); F.reverse()
# print(A); print(F)

l = -1; r = max(A) * max(F)
while r - l > 1:
	m = (l + r) // 2
	if sub(m):
		r = m
	else:
		l = m

print(r)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil

N,K = map(int,input().split())
A = sorted([int(i) for i in input().split()]) # 消化コスト
F = sorted([int(i) for i in input().split()],reverse = True) # 食べにくさ
# K: 修行の回数

cost = [a*f for a,f in zip(A,F)]

# にぶたん
# K回以下の修行でチーム成績がMになるか
# Mを固定して考える
def grade_is(M:int):
    training = 0
    for i in range(N):
        if cost[i] > M:
            training += ceil((cost[i] - M) / F[i])
        if training > K:
            return False
    return True

ok = 10 ** 18 + 1
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if grade_is(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil

N,K = map(int,input().split())
A = sorted([int(i) for i in input().split()]) # 消化コスト
F = sorted([int(i) for i in input().split()],reverse = True) # 食べにくさ
# K: 修行の回数

cost = [a*f for a,f in zip(A,F)]

# にぶたん
# K回以下の修行でチーム成績がMになるか
# Mを固定して考える
def grade_is(M:int):
    training = 0
    for i in range(N):
        if cost[i] > M:
            training += ceil((cost[i] - M) / F[i])
    return training <= K

ok = 10 ** 18 + 1
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if grade_is(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Time Limit Exceeded

Solution code:
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)

def check(x):
    cnt = 0
    for i in range(N):
        tmp = x // sort_F[i]
        cnt += max(0, sort_A[i] - tmp)
    return cnt <= K



def main():
    ok = 10 ** 22
    ng = -1

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid

    print(ok) 

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = [int(c) for c in input().split()]
F = [int(c) for c in input().split()]
A.sort()
F.sort(reverse=True)
M = 0
for i in range(N):
  if A[i]*F[i]>M:
    M = A[i]*F[i]

l = -1
r = M+1
while l+1<r:
  s = (l+r)//2
  cnt = 0
  for i in range(N):
    b = s//F[i]
    cnt += max(0, A[i]-b)
  if cnt>K:
    l = s
  else:
    r = s

print(r)

Submission status: Time Limit Exceeded

Solution code:
import math

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

  lo = 0
  hi = sum(ai * fi for ai, fi in zip(a, f))
  mid = (hi + lo) // 2
  ans = hi

  for i in range(hi):
    cost = sum(max(0, ai - math.floor(mid / fi)) for ai, fi in zip(a,f))
    if k >= cost:
      hi = mid
      ans = mid
    else:
      lo = mid + 1
    if hi == lo:
      break;
    mid = (hi + lo) // 2
  
  print(ans)


if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

lo = 0
hi = sum(ai * fi for ai, fi in zip(a, f))
mid = (hi + lo) // 2
ans = hi

for i in range(hi):
  cost = sum(max(0, ai - math.floor(mid / fi)) for ai, fi in zip(a,f))
  if k >= cost:
    hi = mid
    ans = mid
  else:
    lo = mid + 1
  if hi == lo:
    break;
  mid = (hi + lo) // 2

    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 15:45-
# pdf had been seen

import math

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

lo = 0
hi = sum(ai * fi for ai, fi in zip(a, f))
mid = (hi + lo) // 2
ans = hi

for i in range(hi):
  cost = sum(max(0, ai - math.floor(mid / fi)) for ai, fi in zip(a,f))
  if k >= cost:
    hi = mid
    ans = mid
  else:
    lo = mid + 1
  if hi == lo:
    break;
  mid = (hi + lo) // 2

    
print(ans)