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:
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

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

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

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

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)

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

while right - left > 1:#2分探索で探す。
    mid = (left + right) // 2
    ck = 0#修行回数
    for i in range(n): 
      ck += max(0, a[i] - mid // f[i])# (a[i] - ck) * f[i] = midを解いて左記になる。
    if ck <= k: right = mid
    else: left = 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()))

if k<sum(a):
    a=sorted(a)
    f=sorted(f)[::-1]
    L=[]
    for i in range(n):
        L.append(a[i]*f[i])

    while k>0:
        a.append(a[L.index(max(L))]-1)
        a.pop(L.index(max(L)))
        a=sorted(a)
        L=[]
        for i in range(n):
            L.append(a[i]*f[i])
        k=k-1
    print(max(L))
    
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np


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

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


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


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from math import ceil, floor

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

A.sort()
F.sort()

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

        if md == ed:
            break

    print(md)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np


def main():
    s = input().split(" ")
    N = int(s[0])
    K = int(s[1])
    A = [int(a) for a in input().split(" ")]
    F = [int(a) for a in input().split(" ")]
    A.sort()
    F.sort()
    F.reverse()
    AF = [A[i] * F[i] for i in range(N)]
    idx = np.argsort(AF)[::-1]

    A = [A[idx[i]] for i in range(N)]
    F = [F[idx[i]] for i in range(N)]
    AF = [AF[idx[i]] for i in range(N)]
    m = np.max(AF)

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


def func(saidai, AF, F, N, K):
    count = 0
    for n in range(N):
        if(AF[n] <= saidai):
            return True
        count += math.ceil((AF[n] - saidai) / F[n])
        if(count > K):
            return False
    return True


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

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np


def main():
    s = input().split(" ")
    N = int(s[0])
    K = int(s[1])
    A = [int(a) for a in input().split(" ")]
    F = [int(a) for a in input().split(" ")]
    A.sort()
    F.sort()
    F.reverse()
    AF = [A[i] * F[i] for i in range(N)]
    idx = np.argsort(AF)[::-1]

    A = [A[idx[i]] for i in range(N)]
    F = [F[idx[i]] for i in range(N)]
    AF = [AF[idx[i]] for i in range(N)]
    m = np.max(AF)

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


def func(saidai, AF, F, N, K):
    count = 0
    for n in range(N):
        if(AF[n] <= saidai):
            continue
        count += math.ceil((AF[n] - saidai) / F[n])
        if(count > K):
            return False
    return True


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

Submission status: Time Limit Exceeded

Solution code:
from math import ceil, floor

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

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

if sum(A) <= K:
    print(0)
else:
    st = 0
    ed = 10 ** 12
    md = ceil((st + ed) / 2)
    while True:
        if sum([max(a - floor(md / f), 0) for (a, f) in zip(A, F)]) <= K:
            ed = md
        else:
            st = md
        md = ceil((st + ed) / 2)

        if md == ed:
            break

    print(md)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np


def main():
    s = input().split(" ")
    N = int(s[0])
    K = int(s[1])
    A = [int(a) for a in input().split(" ")]
    F = [int(a) for a in input().split(" ")]
    A.sort()
    F.sort()
    F.reverse()
    AF = [A[i] * F[i] for i in range(N)]
    idx = np.argsort(AF)[::-1]

    A = [A[idx[i]] for i in range(N)]
    F = [F[idx[i]] for i in range(N)]
    AF = [AF[idx[i]] for i in range(N)]
    m = np.max(AF)

    for i in range(m - 1, 0, -1):
        count = 0
        for n in range(N):
            if(AF[n] <= i):
                continue
            count += math.ceil((AF[n] - i) / F[n])
            if(count > K):
                print(i + 1)
                return
    print(0)


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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)
low,high = -1, int(1e12)
while high-low>1:
  mid = (high+low)//2
  k = sum([max(0, a-mid//f) for a,f in zip(A,F)])
  if k>K: low = mid
  else: high = mid
print(high)

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)
low,high = -1, max([a*f for a,f in zip(A,F)])
while high-low>1:
  mid = (high+low)//2
  k = sum([max(0, a-mid//f) for a,f in zip(A,F)])
  if k>K: low = mid
  else: high = mid
print(high)

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)
low,high = -1, max(map(lambda x,y:x*y, A,F))
while high-low>1:
  mid = (high+low)//2
  k = sum([a-min(a,mid//f) for a,f in zip(A,F)])
  if k>K: low = mid
  else: high = mid
print(high)

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)
low,high = -1, max(map(lambda x,y:x*y, A,F))
while high-low>1:
  mid = (high+low)//2
  k = sum(map(lambda x,y: x-min(x,mid//y), A,F))
  if k>K: low = mid
  else: high = mid
print(high)

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)
low,high = -1, max(map(lambda x,y:x*y, A,F))
while high-low>1:
  mid = (high+low)//2
  k = sum(map(lambda x,y:x-y,A,map(lambda x,y:min(x,y),map(lambda x: mid//x,F), A)))
  if k>K: low = mid
  else: high = mid
print(high)

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)

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

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

print(right)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if sum(max(A[i]-xm//F[i] ,0) for i in range(0,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq
from collections import deque
import sys
readline = sys.stdin.readline


def main():
    n,k = map(int,readline().split())
    A = list(map(int,readline().split()))
    F = list(map(int,readline().split()))
    A.sort()
    F.sort(reverse=True)
    
    s = [(-a*f,a,f) for a,f in zip(A,F)]
    hq.heapify(s)
    for _ in range(k):
        point,a,f= hq.heappop(s)
        if a > 0:
            point = point+f
            a = a -1
            hq.heappush(s,(point,a,f))
        else:
            hq.heappush(s,(point,a,f))
    point,a,f = hq.heappop(s)
    print(-point)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq
from collections import deque
import sys
readline = sys.stdin.readline

n,k = map(int,readline().split())
A = list(map(int,readline().split()))
F = list(map(int,readline().split()))
A.sort()
F.sort(reverse=True)

s = [(-a*f,a,f) for a,f in zip(A,F)]
hq.heapify(s)
for _ in range(k):
    point,a,f= hq.heappop(s)
    if a > 0:
        point = point+f
        a = a -1
        hq.heappush(s,(point,a,f))
    else:
        hq.heappush(s,(point,a,f))
point,a,f = hq.heappop(s)
print(-point)

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq
from collections import deque

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

s = []
for a,f in zip(A,F):
    s.append((-a*f,a,f))
hq.heapify(s)
for _ in range(k):
    point,a,f= hq.heappop(s)
    if a > 0:
        point = point+f
        a = a -1
        hq.heappush(s,(point,a,f))
    else:
        hq.heappush(s,(point,a,f))
point,a,f = hq.heappop(s)
print(-point)

Submission status: Time Limit Exceeded

Solution code:
def isOK(score):
    min_cost = sum_a - sum([min(A,score // F) for A,F in zip(a,f)])
    if min_cost <= k:
        return True
    else:
        return False


def binary_search():
    ok = 10 ** 12 + 100
    ng = -1
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if isOK(mid):
            ok = mid
        else:
            ng = mid
    return ok



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

sum_a = sum(a)
ans = binary_search()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.sort(A)
F = np.sort(F)[::-1]
Amax = A[-1]
Fmax = F[0]
x=0

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

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq
from collections import deque

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

s = []
for a,f in zip(A,F):
    hq.heappush(s,(-a*f,a,f))

for _ in range(k):
    point,a,f= hq.heappop(s)
    if a > 0:
        point = point+f
        a = a -1
        hq.heappush(s,(point,a,f))
    else:
        hq.heappush(s,(point,a,f))
point,a,f = hq.heappop(s)
print(-point)

Submission status: Time Limit Exceeded

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

A = tuple(sorted(Al))
F = tuple(sorted(Fl,reverse = True))
Amax = A[-1]
Fmax = F[0]
x=0

def maxA2(AA, FF, NN):
    i=0
    while i < NN:
        yield max(A[i]-xm//F[i] ,0)
        i += 1


if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if sum(maxA2(A,F,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Submission status: Time Limit Exceeded

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

A = tuple(sorted(Al))
F = tuple(sorted(Fl,reverse = True))
Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if sum(max(A[i]-xm//F[i] ,0) for i in range(0,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, nt = map(int, input().split())
ms = np.sort(np.array(list(map(int, input().split()))))
fs = np.sort(np.array(list(sorted(map(int, input().split())))))[::-1]
r = ms*fs

for i in range(nt):
  idx = np.argmax(r)
  if ms[idx] < 1:
    break
  ms[idx] -= 1
  r[idx] = ms[idx] * fs[idx]

print(np.max(ms*fs))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, nt = map(int, input().split())
ms = np.array(list(sorted(map(int, input().split()))))
fs = np.array(list(reversed(sorted(map(int, input().split())))))
r = ms*fs

for i in range(nt):
  idx = np.argmax(r)
  if ms[idx] < 1:
    break
  ms[idx] -= 1
  r[idx] = ms[idx] * fs[idx]

print(np.max(ms*fs))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, nt = map(int, input().split())
ms = np.array(list(sorted(map(int, input().split()))))
fs = np.array(list(reversed(sorted(map(int, input().split())))))

for i in range(nt):
  idx = np.argmax(ms*fs)
  if ms[idx] < 1:
    break
  ms[idx] -= 1

print(np.max(ms*fs))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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)
P = [A[i]*F[i] for i in range(n)]

if sum(A) <= k: print('0')
else:
    new_P = list(A)
    i=0
    while k < sum(new_P):
        for j in range(n):
            if (P[j] - i) > 0: new_P[j] = (P[j] - i) // F[j] + 1
            else: new_P[j] = 0
        i += 1
        
    for h in range(n):
        P[h] -= F[h]*new_P[h]
        
    d = k - sum(new_P)
    if d > 0:
        for di in range(d):
            m = max(P)
            mi = P.index(m)
            P[mi] -= F[mi]      
        
    print(max(P))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = sorted([int(x) for x in input().split()])
f = sorted([int(x) for x in input().split()])

c = [a[i]*f[n-i-1] for i in range(n)]

for i in range(k):
    # 一番完食に時間がかかるメンバーが修業
    idx = c.index(max(c))      
    a[idx] -= 1
    c[idx] = a[idx] * f[n-idx-1]

print(max(c))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, k = map(int, input().split())
a = sorted([int(x) for x in input().split()])
f = sorted([int(x) for x in input().split()])

c = [a[i]*f[n-i-1] for i in range(n)]

for i in range(k):
    # 一番完食に時間がかかるメンバーが修業
    idx = c.index(max(c))              # 完食に一番時間がかかるメンバー
    p = a.pop(idx)                     # リストから外す
    idx2 = bisect.bisect_right(a, p-1) # リストに戻す場所
    a.insert(idx2, p-1)                # 1減らしてもどす
    # 再びメンバーごとの必要時間を求める
    c[idx] = a[idx]*f[n-idx-1] 
    c[idx2] = a[idx2]*f[n-idx2-1]

print(max(c))

Submission status: Time Limit Exceeded

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

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

A.sort()
F.sort(reverse = True)
G = [A[i]*F[i] for i in range(N)]

for i in range(K):
    g = G.index(max(G))
    A[g] -= 1
    G[g] = A[g] * F[g]

print(max(G))

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect

n, k = map(int, input().split())
a = sorted([int(x) for x in input().split()])
f = sorted([int(x) for x in input().split()])


#print('a=', sorted(a, reverse=True))
#print('f=', f)


c = [[a[n-i-1]*f[i], i] for i in range(n)]
#print([a[n-i-1]*f[i] for i in range(n)])

for i in range(k):
    # 一番完食に時間がかかるメンバーが修業
    idx = c.index(max(c))
    p = a.pop(n-idx-1)   # メンバーを指定
    bisect.insort(a, p-1)# 1減らしてもどす
    # 再びメンバーごとの必要時間を求める
    c = [[a[n-i-1]*f[i], i] for i in range(n)]    
    #c.sort(reverse=True)


t = max([cost for [cost, idx] in c])
print(t)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
import numpy as np
#import operator
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	NKAF=np.array(read().split(),np.int64)
	N=NKAF[0]
	K=NKAF[1]
	AF=NKAF[2:]
	A,F=np.split(AF,2)
	A.sort()
	F.sort()
	F=F[::-1]
	
	lt=0
	rt=10**12+1
	
	Asum=sum(A)
	
	while rt-lt>1:
		mid=(rt+lt)//2
		if Asum-sum(np.minimum(A,mid//F))<=K:
			rt=mid
		else:
			lt=mid
	print(rt if Asum-K>0 else 0)
	
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()))

A.sort()
F.sort(reverse = True)
Amax = A[-1]
Fmax = F[0]

x=0
if sum(A) < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if sum(max(A[i]-xm//F[i] ,0) for i in range(0,N)) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

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 = -1
r = 10**12

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

Submission status: Time Limit Exceeded

Solution code:
import sys

n, k = map(int, input().split())
a = sorted([int(x) for x in input().split()], reverse=True)
f = sorted([int(x) for x in input().split()])

c = [[a[i]*f[i], i] for i in range(n)]
c.sort(reverse=True)

for i in range(k):
    [count, idx] = c[0]
    a[idx] -= 1
    c = [[a[i]*f[i], i] for i in range(n)]    
    c.sort(reverse=True)

t = max([cost for [cost, idx] in c])
print(t)

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
BCs = [(b,a*b) for a,b in zip(sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1])]

def f(target):
    return sum([math.ceil(max(0, c - target)/b)for b, c in BCs])<=K

if __name__ == '__main__':
    min_i, max_i, index = 0, 10**12, 1
    while True:
        index, max_i, min_i = ((index-1 + min_i)//2, index-1, min_i) if f(index) else ((index+1 + max_i)//2, max_i, index+1)
        if min_i > max_i:
            print(min_i)
            break

Submission status: Time Limit Exceeded

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
        else:
            index, min_i = (index+1 + max_i)//2, index+1
        if min_i > max_i:
            print(min_i)
            break

Submission status: Time Limit Exceeded

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

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

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
    d = set()
    while True:
        d.add(index)
        if func(index):
            index, max_i = (index-1 + min_i)//2, index-1
            continue
        if index+1 in d:
            print(index+1)
            break
        index, min_i = (index+1 + max_i)//2, index+1

Submission status: Time Limit Exceeded

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 not func(index):
            if func(index+1):
                print(index+1)
                break
            index, min_i = (index+1 + max_i)//2, index+1
            continue
        index, max_i = (index-1 + min_i)//2, index-1

Submission status: Time Limit Exceeded

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 = 0, max(Cs)+1
    index = (max_i + min_i)//2
    while True:
        if not func(index):
            if func(index+1):
                print(index+1)
                break
            index, min_i = (index+1 + max_i)//2, index+1
            continue
        index, max_i = (index-1 + min_i)//2, index-1

Submission status: Time Limit Exceeded

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 int(r <= K)

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

Submission status: Time Limit Exceeded

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):
    return sum([math.ceil(max(0, c - target) / b) for b, c in BCs]) <= K

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

Submission status: Time Limit Exceeded

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 int(r <= K)

def bsearch():
    min_i, max_i = 0, max(Cs)+1
    target = 0
    # func(index) <= target < func(index+1) となるindexを返す
    index = (max_i + min_i)//2
    while True:
        if func(index) <= target:
            if target < func(index+1):
                return index + 1
            index, min_i = (index+1 + max_i)//2, index+1
            continue
        index, max_i = (index-1 + min_i)//2, index-1

if __name__ == '__main__':
    print(bsearch())

Submission status: Time Limit Exceeded

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)]
ABs = list(zip(As, Bs, Cs))

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

def bsearch():
    min_i, max_i = 0, max(Cs)+1
    target = 0
    # func(index) <= target < func(index+1) となるindexを返す
    index = (max_i + min_i)//2
    while True:
        if func(index) <= target:
            if target < func(index+1):
                return index + 1
            index, min_i = (index+1 + max_i)//2, index+1
            continue
        index, max_i = (index-1 + min_i)//2, index-1

if __name__ == '__main__':
    print(bsearch())

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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)

P = [A[i]*F[i] for i in range(n)]

if sum(A) <= k: print('0')
else:
    for j in range(k):
        max_value = max(P)
        max_index = P.index(max_value)
        A[max_index] -= 1
        P[max_index] = A[max_index]*F[max_index]
    print(max(P))