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:
n,k = map(int,input().split())
a = [i for i in map(int,input().split())]
f = [i for i in map(int,input().split())]
r = []

a.sort()
f.sort(reverse=True)

for i in range(0,n):
	r.append(a[i]*f[i])

for i in range(0,k):
	r[r.index(max(r))] -= f[r.index(max(r))]

print(max(r))

Submission status: Time Limit Exceeded

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


def is_ok(mid, K, A, F):
    used = 0
    for a, f in zip(A, F):
        upper = int(mid / f)
        if upper < a:
            used += a - upper
        if K < used:
            return False
    return True


def main():
    N, K = input_line(int, int)
    A = input_line([int])
    F = input_line([int])
    A.sort()
    F.sort(reverse=True)

    ng = -1
    ok = int(1e12)
    while ok - ng > 1:
        mid = (ng + ok) // 2
        if is_ok(mid, K, A, F):
            ok = mid
        else:
            ng = mid
    print(ok)


def input_line(*types):
    if isinstance(types[0], list):
        return list(map(types[0][0], input().split()))
    elif len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


def argmax(scores):
    index = 0
    mx = 0
    for i, s in enumerate(scores):
        if mx < s[0]:
            mx = s[0]
            index = i
    return index


def main():
    N, K = input_line(int, int)
    A = input_line([int])
    F = input_line([int])
    A.sort()
    F.sort(reverse=True)
    scores = [[a*f, a, f] for a, f in zip(A, F)]
    index = argmax(scores)
    while K > 0 and scores[index][1] > 0:
        scores[index][1] -= 1
        scores[index][0] = scores[index][1] * scores[index][2]
        K -= 1
        index = argmax(scores)
    print(scores[index][0])


def input_line(*types):
    if isinstance(types[0], list):
        return list(map(types[0][0], input().split()))
    elif len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


def argmax(scores):
    index = 0
    mx = 0
    for i, s in enumerate(scores):
        if mx < s[0]:
            mx = s[0]
            index = i
    return index


def main():
    N, K = input_line(int, int)
    A = input_line(*[int for i in range(N)])
    F = input_line(*[int for i in range(N)])
    A.sort()
    F.sort(reverse=True)
    scores = [[a*f, a, f] for a, f in zip(A, F)]
    scores.sort(key=lambda x: x[0], reverse=True)
    index = argmax(scores)
    while K > 0 and scores[index][1] > 0:
        scores[index][1] -= 1
        scores[index][0] = scores[index][1] * scores[index][2]
        K -= 1
        index = argmax(scores)
    print(scores[index][0])


def input_line(*types):
    if len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


def main():
    N, K = input_line(int, int)
    A = input_line(*[int for i in range(N)])
    F = input_line(*[int for i in range(N)])
    A.sort()
    F.sort(reverse=True)
    scores = [[a*f, a, f] for a, f in zip(A, F)]
    scores.sort(key=lambda x: x[0], reverse=True)
    while K > 0 and scores[0][1] > 0:
        scores[0][1] -= 1
        scores[0][0] = scores[0][1] * scores[0][2]
        K -= 1
        scores.sort(key=lambda x: x[0], reverse=True)
    print(scores[0][0])


def input_line(*types):
    if len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


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)

l = 0
r = max(a * f for a, f in zip(A, F)) + 1

while l < r:
    m = (l + r) // 2
    if sum(max(a - m // f, 0) for a, f in zip(A, F)) <= K:
        r = m
    else:
        l = m + 1

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)

l = 0
r = 10**12 + 1

while l < r:
    m = (l + r) // 2
    if sum(max(a - m // f, 0) for a, f in zip(A, F)) <= K:
        r = m
    else:
        l = m + 1

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(reverse=True)
F.sort()
scores = [x * y for x, y in zip(A, F)]
scores = list(zip(scores, A, F))

while K > 0 and any(s[0] > 0 for s in scores):
    max_score = max(scores)
    index = scores.index(max_score)
    max_score = list(max_score)
    max_score[0] -= max_score[2]
    max_score[1] -= 1
    scores[index] = tuple(max_score)
    K -= 1

print(max(scores)[0])

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)

l = 0
r = 1000000000000
while l < r:
    m = (l+r)//2
    c = 0
    for a, f in zip(A, F):
        c += max(a-m//f, 0)
    if K < c:
        l = m+1
    else:
        r = m
print(r)

Submission status: Time Limit Exceeded

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

def check(x, a=A, f=F, k=K):
  S = sum([max(ai - x//fi, 0) for ai, fi in zip(a, f)])
  if S > k:
    result = False
  else:
    result = True
  
  return result


l, r = 0, 10**12
m = (l + r) // 2

while True:
  result = check(m)
  if result:
    r = m
  else:
    l = m
  
  m = (l + r) // 2
  if r == l + 1:
    if check(l):
      x = l
    else:
      x = r
    break

print(x)

Submission status: Time Limit Exceeded

Solution code:
n, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = 0, a[-1] * b[0]
while l <= r:
    m = (l + r) // 2
    t = 0
    for i in range(n):
        t += max(a[i] - m // b[i], 0)
    if t > k:
        l = m + 1
    else:
        r = m - 1
print(l)

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についても、修行前の大小で並べてしまって良いです
A=np.array(sorted(a))
F=np.array(sorted(f, reverse=True))
#最大値の最小化▶︎二分探索！
#答えxを決めて、A*Fペア全てをx以下にするために必要な修行がk回以下かを調べていく。(xについて二分探索)
left=-1
right=10**12
s=A.sum()
x=(left+right)//2
#A-x//Fは、x以下にするのに必要な最小の修行回数。
#np.maximum(A-x//F,0)は、２つの配列の大きい方を取っていきながらあたらしい配列を作っている。
while left+1<right:
    if s-np.minimum(A , x//F).sum()<=k:
        #この時答えはx以下なので
        right=x
    else:
        #この時答えはxより大きいので
        left=x
print(right)

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についても、修行前の大小で並べてしまって良いです
A=np.array(sorted(a))
F=np.array(sorted(f, reverse=True))
#最大値の最小化▶︎二分探索！
#答えxを決めて、A*Fペア全てをx以下にするために必要な修行がk回以下かを調べていく。(xについて二分探索)
left=-1
right=10**12
s=A.sum()
x=(left+right)//2
#A-x//Fは、x以下にするのに必要な最小の修行回数。
#np.maximum(A-x//F,0)は、２つの配列の大きい方を取っていきながらあたらしい配列を作っている。
while left+1<right:
    if np.maximum(A-x//F,0).sum()<=k:
        #この時答えはx以下なので
        right=x
    else:
        #この時答えはxより大きいので
        left=x
print(right)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort()
b.sort(reverse=True)


def ok(mid,a,b,k,n):
    tmp = 0
    for i in range(n):
        if a[i] * b[i] > mid:
            tmp += a[i] - mid//b[i]
    if tmp > k:
        return 1
    else:
        return -1


def bin_search(a,b,k,n):
    l = 0
    r = 10**20
    while l <= r:
        mid = l + (r - l)//2
        res = ok(mid,a,b,k,n)
        if res < 0:
            r = mid - 1
        else:
            l = mid + 1
    return l


print(bin_search(a,b,k,n))

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

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

print(r)

Submission status: Time Limit Exceeded

Solution code:
listNK = list(map(int, input().split()))
A_i = list(map(int, input().split()))
F_i = list(map(int, input().split()))
N = listNK[0]
K = listNK[1]
list.sort(A_i)
list.sort(F_i, reverse=True)
score = [0] * N
while K > 0 and A_i[N-1] > 0:
    MaxScore = 0
    for i in range(N):
        score[i] = A_i[i] * F_i[i]
        if score[i] > MaxScore:
            index = i
            MaxScore = score[i]
    A_i[index] = A_i[index] - 1
    K = K - 1
    list.sort(A_i)
MaxScore = 0
for i in range(N):
    score[i] = A_i[i] * F_i[i]
    if score[i] > MaxScore:
        index = i
        MaxScore = score[i]
print(MaxScore)

Submission status: Time Limit Exceeded

Solution code:
listNK = list(map(int, input().split()))
A_i = list(map(int, input().split()))
F_i = list(map(int, input().split()))
N = listNK[0]
K = listNK[1]
list.sort(A_i)
list.sort(F_i, reverse=True)
score = [0] * N
while K > 0 and A_i[N-1] > 0:
    for i in range(N):
        score[i] = A_i[i] * F_i[i]
    MaxScore = max(score)
    for i in range(N):
        if score[i] == MaxScore:
            index = i
            break
    A_i[index] = A_i[index] - 1
    K = K - 1
    list.sort(A_i)
for i in range(N):
        score[i] = A_i[i] * F_i[i]
MaxScore = max(score)
print(MaxScore)

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()))
B=[]
D=[]
A.sort(reverse=True)
F.sort()
max=A[0]*F[0]-1
for i in range(N):
  B.append(A[i]*F[i])
  if(max<A[i]*F[i]):
    max=A[i]*F[i]
    D.clear()
  if(max==A[i]*F[i]):
    D.append(i)
while(K>=len(D)):
  for i in D:
    B[i]-=F[i]
    K-=1
  max=B[0]-1
  for i in range(N):
    if(max<B[i]):
      max=B[i]
      D.clear()
    if(max==B[i]):
      D.append(i)
print(max)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N, K = mis()
    A = lmis()
    A.sort(reverse=True)
    F = lmis()
    F.sort()
    #
    class solver:
        def __getitem__(self, score_limit):
            k = K
            for i in range(N):
                if A[i]*F[i] > score_limit:
                    k -= A[i] - score_limit//F[i]
                    if k < 0:
                        return False
            return True
        def __len__(self):
            return max(A)*max(F)
    #
    import bisect
    print(bisect.bisect_left(solver(), True))

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N, K = mis()
    A = lmis()
    A.sort(reverse=True)
    F = lmis()
    F.sort()
    #
    class solver:
        def __getitem__(self, score_limit):
            k = K
            for i in range(N):
                if A[i]*F[i] > score_limit:
                    k -= A[i] - score_limit//F[i]
                    if k < 0:
                        return False
            return True
        def __len__(self):
            return (10**6)**2
    #
    import bisect
    print(bisect.bisect_left(solver(), True))

main()

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
F = list(map(int, sys.stdin.readline().split()))

if N == 1:
    a = A[0]
    f = F[0]
    ans = max(a - K, 0) * f
    print(ans)
    exit()

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

heap = []
for a, f in zip(A, F):
    heap.append((-a * f, a, f))
heapq.heapify(heap)

while K > 0:
    _, a, f = heapq.heappop(heap)
    if a == 0:
        break
    af2 = -heap[0][0]
    next_a = max(0, math.ceil(af2 / f) - 1)
    k = min(K, a - next_a)
    K -= k
    a -= k
    heapq.heappush(heap, (-a * f, a, f))

ans = 0
for af, _, _ in heap:
    ans = max(ans, -af)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
F = list(map(int, sys.stdin.readline().split()))

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

heap = []
for a, f in zip(A, F):
    heap.append((-a * f, a, f))
heapq.heapify(heap)
for _ in range(K):
    _, a, f = heap[0]
    if a == 0:
        break
    a -= 1
    heapq.heapreplace(heap, (-a * f, a, f))

ans = 0
for af, _, _ in heap:
    ans = max(ans, -af)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
NK = input().split(' ')
N = int(NK[0])
K = int(NK[1])
An = sorted(tuple(map(int,input().split(' '))))
Fn = sorted(tuple(map(int,input().split(' '))),reverse=True)
An_s = sum(An)

min_time = -1 #middle_time = 0を含めるので -1
max_time = An[N-1] * Fn[0] #最大でかかる時間
x_cadidate = An[N-1] * Fn[0] #xの最小の候補
middle_time = -1
range_n = range(N)
#init_list = [0]*N
while True:
    # max_time+1は max_time=0まで求めるため
    middle_time = (min_time + max_time)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    #new_list = init_list
    sum_ax = 0
    for i in range_n:
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            sum_ax += ax
        else:
            sum_ax += An[i]
    if  min_time+1 == max_time: #二部探索で全てを探索したら終了 
        break
    elif An_s - sum_ax <= K:
        if x_cadidate > middle_time:
            x_cadidate = middle_time 
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい

print(x_cadidate)

Submission status: Time Limit Exceeded

Solution code:
NK = input().split(' ')
N = int(NK[0])
K = int(NK[1])
An = sorted(list(map(int,input().split(' '))))
Fn = sorted(list(map(int,input().split(' '))),reverse=True)
An_s = sum(An)
#print(An)
#print(Fn)

min_time = -1 #middle_time = 0を含めるので -1
max_time = An[N-1] * Fn[0] #最大でかかる時間
x_cadidate = An[N-1] * Fn[0] #xの最小の候補
middle_time = -1
range_n = range(N)
#init_list = [0]*N
while True:
    # max_time+1は max_time=0まで求めるため
    middle_time = (min_time + max_time)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    #new_list = init_list
    sum_ax = 0
    for i in range_n:
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            sum_ax += ax
        else:
            sum_ax += An[i]
    if  min_time+1 == max_time: #An_s - sum_candisum_axdate == K or
        break
    elif An_s - sum_ax <= K:
        if x_cadidate > middle_time:
            x_cadidate = middle_time 
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい

print(x_cadidate)

Submission status: Time Limit Exceeded

Solution code:
def isok(A_, F_, N_, K_, x):
  _K_ = 0
  for i in range(N_):
    a_ = A_[i]-x//F_[i]
    if a_ > 0:
      _K_ += a_
  if _K_ > K_:
  	return False
  else:
    return True

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse = True)
ok = 10**12
ng = 0
while abs(ok-ng)>1:
  mid_x = (ok+ng)//2
  if isok(A, F, N, K, mid_x):
    ok = mid_x
  else:
    ng = mid_x
if isok(A, F, N, K, ng):
  print(ng)
else:
  print(ok)

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()))[::-1]

left,right=-1,10**12
while left + 1 < right:
    mid = (left + right)//2
    if sum([max(0,a-mid//f) for a,f in zip(A,F)])>K:
        left = mid
    else:
        right = mid
print(right)

Submission status: Time Limit Exceeded

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=A[-1]*F[0]
ng=-1
while(ng+1<ok):
  c=ng+(ok-ng)//2
  if is_ok(c):
    ok=c
  else:
    ng=c

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())),reverse=True)
ok=A[-1]*F[0]
ng=-1
while(ng+1<ok):
  c=ng+(ok-ng)//2
  sum=0
  for i in range(N):
    if(A[i] - c//F[i]>=0):
      sum += A[i] - c//F[i]
  if(sum<=K):
    ok=c
  else:
    ng=c
 
print(ok)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr1=sorted(arr1)
arr2=list(map(int,input().split()))
arr2=sorted(arr2,reverse=True)
l=-1
r=10**12+1
while r-l!=1:
  m=(r+l)//2
  tmp=0
  for i in range(n):
    if arr1[i]>m//arr2[i]:
      tmp+=(arr1[i]-m//arr2[i])
  if tmp<=k:
    r=m
  else:
    l=m
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(reverse=True)
F.sort()
ng=-1
ok=10**18+1
while ok-ng>1:
             mid=(ng+ok)//2
             k=K
             for a,f in zip(A,F):
                     k-=max(0,a-mid//f)
             if k<0:
                 ng=mid
             else:
                ok=mid
print(ok)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
F = [int(i) for i in input().split()]
F.sort()
"""
n = 11
k = 14
A = [1,1,2,3,3,4,5,5,5,6,9]
F = [9,9,8,8,7,6,4,3,3,2,2]
"""

 
P = [A[i]*F[i] for i in range(n)]
sum_A = sum(A)
 
def b(p):
    result = 0
    for i in range(n):
        if P[i] > p:
            r = (P[i] - p) // F[i]
            if P[i] - r * F[i] > p:
                r += 1
            result += r
    return result
 
if sum_A <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = int((left + right) / 2)
    bm = b(middle)
    
    
    
    while right - left > 1:
        
        if bm > k: left = middle
        else: right = middle
            
        middle = int((left + right) / 2)
        bm = b(middle)
 
    if b(left) <= k: print(left)
    else: print(right)

Submission status: Time Limit Exceeded

Solution code:
import os
import sys
from io import BytesIO

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))

n, k = map(int, sys.stdin.readline().split())
a = map(int, sys.stdin.readline().split())
f = map(int, sys.stdin.readline().split())
a.sort()
f.sort(reverse=True)

'''
n, k = 100000, 0
a = range(n)
f = range(n)
a.sort()
f.sort(reverse=True)

print n, k

for i in range(n):
	print 1,
print

for i in range(n):
	print 1,
print
'''


def val(p):
	r = 0
	for i in range(n):
		t = 0 if a[i] * f[i] <= p else a[i] - p // f[i]
		r += t
	return r
		
def bin(l, r):
	if l == r:
		return l
	if l + 1 == r:
		if val(l) <= k:
			return l
		else:
			return r
	t = (l + r) // 2
	if val(t) <= k:
		return bin(l, t)
	else:
		return bin(t, r)
		
R = bin(0, 1000000000000)
print(R)

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)

low = -1
high = 10**12

while high - low > 1:
    score = (low+high)//2
    training = 0
    for i in range(n):
        if A[i]*F[i] > score:
            training += A[i] - score//F[i]
    if training <= k:
        high = score
    else:
        low = score
        
print(high)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)

left = -1
right = 10**18+1
 
 
while right - left > 1:
    mid = left + (right - left) // 2
 
 
    train = k
    for i in range(n):
        req = mid // f[i]
        if req < a[i]:
            train -= a[i] - req
 
 
    if train >= 0:
        right = mid
    else:
        left = mid
 
 
 
print(right)

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)

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

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

n,k = map(int, input().split())
# lstA = list(map(int, input().split()))
# lstF = list(map(int, input().split()))
# lstA.sort()
# lstF.sort()
# lstF.reverse()
lstA = np.array(sorted(list(map(int, input().split()))))
lstF = np.array(sorted(list(map(int, input().split())), reverse=True))

def check(x):
    checker = 0
    for i in range(n):
        checker += math.ceil(lstA[i]-x/lstF[i])
    if checker <= k:
        return True
    else:
        return False

left = -1
right = 10**12

while True:
    center = (left+right)//2
    if check(center) == True:
        right = center
    else:
        left = center
    if right <= left+1:
        print(right)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

n,k = map(int, input().split())
lstA = list(map(int, input().split()))
lstF = list(map(int, input().split()))

# lstA.sort()
# lstF.sort()
# lstF.reverse()
lstA = np.sort(lstA)
lstF = np.sort(lstF)[::-1]

def check(x):
    checker = 0
    for i in range(n):
        checker += math.ceil(lstA[i]-x/lstF[i])
    if checker <= k:
        return True
    else:
        return False

left = -1
right = 10**12

while left <= right:
    center = (left+right)//2
    if check(center) == True:
        right = center
    else:
        left = center
    if right <= left+1:
        print(right)
        exit()

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:
        c=max(L)
        d=L.index(c)
        b=a[d]
        a.pop(d)
        a.insert(d,b-1)
        L.pop(d)
        L.insert(d,(b-1)*f[d])
        k=k-1
    print(max(L))
    
else:
    print(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 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:
        c=max(L)
        d=L.index(c)
        b=a[d]
        a.pop(d)
        a.insert(d,b-1)
        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:
from operator import mul

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

A.sort()
F.sort(reverse = True)
cost = [0]*N

for i in range(K+1):
  cost = list(map(mul, A, F))
  if cost == [0]*N:
    break
  A[cost.index(max(cost))] -= 1

print(max(cost))

Submission status: Time Limit Exceeded

Solution code:
import math

n,k = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
f = list(map(int, input().strip().split()))
a.sort()
f.sort()
#f = f[::-1]
af = [[] for i in range(n)]
r = 0
for i in range(n):
	af[i] = [a[n-1-i]*f[i], f[i]]
	r = max(r, af[i][0])
af.sort()
af = af[::-1]

#r = af[0][0]
l = 0
while l < r:
	c = (l+r)//2
	training = 0
	for e in af:
		if c >= e[0] or k < training:
			break
		training += (e[0]-c + e[1]-1) // e[1]
	if training <= k:
		r = c
	else:
		l = c+1
print(l)

Submission status: Time Limit Exceeded

Solution code:
import math

n,k = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
f = list(map(int, input().strip().split()))
a.sort()
f.sort()
f = f[::-1]
af = []
for i in range(n):
	af.append([a[i]*f[i], f[i]])
af.sort()
af = af[::-1]

r = af[0][0]
l = 0
while l < r:
	c = (l+r)//2
	training = 0
	for e in af:
		if c < e[0]:
			training += (e[0]-c + e[1]-1) // e[1]
	if training <= k:
		r = c
	else:
		l = c+1
print(l)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    f = list(map(int, input().split()))
    f.sort()
    right = a[0]*f[-1]
    left = 0
    while right > left:
        middle = (right + left)//2
        b = 0
        
        for i in range(n):
            b += max(0, a[i] - middle//f[i])
        if b <= k:
            right = middle
        else:
            left = middle+1

    print(right)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    f = list(map(int, input().split()))
    f.sort()
    right = 10**12
    left = 0
    while right > left:
        middle = (right + left)//2
        b = 0
        
        for i in range(n):
            b += max(0, a[i]-(middle//f[i]))
        if b <= k:
            right = middle
        else:
            left = middle + 1

    print(right)
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.sort()
F.sort()
F = F[::-1]
s=sum(A)
l=-1
r=10**12+2
while l+1<r:
    m=(l+r)//2
    temp = s
    for i in range(N):
      temp -= min(A[i],m//F[i])
    if temp <= K:
        r=m
    else:
        l=m
print(r)

Submission status: Time Limit Exceeded

Solution code:
import math
n, k = map(int, input().split())
# a = [int(x) for x in input().split()]
# f = [int(x) for x in input().split()]
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
lx = 0
rx = a[-1] * f[0]
for i in range(1000):
    if lx == rx:
        break
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        ta = a[j]
        y = (ta*f[j] - cx + f[j] -1) // f[j]
        kk += max(0, y)
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)

Submission status: Time Limit Exceeded

Solution code:
import math
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
a.sort()
f.sort(reverse=True)
lx = 0
rx = a[-1] * f[0]
for i in range(1000):
    if lx == rx:
        break
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        ta = a[j]
        y = (ta*f[j] - cx + f[j] -1) // f[j]
        kk += max(0, y)
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)

Submission status: Time Limit Exceeded

Solution code:
import math
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
a.sort()
f.sort(reverse=True)
lx = 0
rx = 10 ** 12
for i in range(1000):
    if lx == rx:
        break
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        ta = a[j]
        y = (ta*f[j] - cx + f[j] -1) // f[j]
        kk += max(0, y)
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
a.sort()
f.sort(reverse=True)
lx = 0
rx = 10 ** 12
for i in range(1000):
    if lx == rx:
        break
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        ta = a[j]
        while(ta*f[j] > cx):
            ta -= 1
            kk += 1
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)

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()))
f.sort()
a.sort(reverse=True)
x = 0
l = []
for i in range(n):
    l.append(a[i]*f[i])
m = max(l)
nibu = [0,m]
while nibu[0]+1 < nibu[1]:
    p = (nibu[0]+nibu[1])//2
    count = 0
    for i in range(n):
        if p < l[i]:
            count += (l[i]-p)//f[i]
            if (l[i]-p)%f[i] > 0:
                count += 1
    if count > k:
        nibu[0] = p
    else:
        nibu[1] = p
count = 0
p = nibu[0]
#print(a,f)
for i in range(n):
    if p < l[i]:
        count += (l[i]-p)//f[i]
        if (l[i]-p)%f[i] > 0:
            count += 1
    #print(count)
if count > k:
    print(nibu[1])
else:
    print(nibu[0])