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:
from heapq import heappop, heappush, heapify

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)

h = [(-1 * a * f, a, f) for (a, f) in zip(A, F)]
heapify(h)

for k in range(K):
    if h[0][1] == 0:
        break
    a = heappop(h)
    heappush(h, (-1 * (a[1] - 1) * a[2], a[1] - 1, a[2]))

print(-1 * heappop(h)[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.sort()
F.sort(reverse=True)

start = -1
end = A[-1] * F[0]

def check(now):
    cnt = 0
    for i in range(N):
        if A[i] * F[i] > now:
            cnt += (A[i]*F[i] - now + F[i] - 1) // F[i]
    if cnt > K:
        return False
    return True

while end > start + 1:
    now = (start + end) // 2
    if check(now):
        end = now
    else:
        start = now

print(end)

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)

q = [0] * N
start = -1
end = 0
for i in range(N):
    q[i] = A[i] * F[i]
    end = max(end, q[i])

def check(now, K):
    cnt = 0
    for i in range(N):
        if q[i] - now > 0:
            cnt += (q[i] - now + F[i] - 1) // F[i]
            if cnt > K:
                return False
    return True

now = end // 2
while end > start + 1:
    if check(now, K):
        end = now
    else:
        start = now
    now = (start + end) // 2

print(end)

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)

q = [0] * N
start = 0
end = 0
for i in range(N):
    q[i] = A[i] * F[i]
    end = max(end, q[i])

def check(now, K):
    cnt = 0
    for i in range(N):
        if q[i] - now > 0:
            cnt += (q[i] - now + F[i] - 1) // F[i]
            if cnt > K:
                return False
    return True

now = end // 2
while end > start + 1:
    if check(now, K):
        end = now
    else:
        start = now
    now = (start + end) // 2

if check(start, K):
    print(start)
else:
    print(end)

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


def func(x):
    k = 0  # 修行回数初期化
    for a, f in zip(A, F): # O(N)
        if a <= x // f:  # (Ai-Ki)*Fi<=x Ki=0なら次 (a*f<=xの変形)
            continue
        k += a - x // f
        # else (Ai-Ki)*Fi<=x を満たすようにKiを設定。つまり修行回数にKiを加算。
    if k <= K:
        return 1
    return 0


while (r - l > 1): # O(logx)
    mid = (l + r) // 2
    if func(mid):
        r = mid
    else:
        l = mid


print(r)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq


def can_eat_with_score(key):
    now_K = K
    for i, now_score in enumerate(score):
        if key < now_score:
            now_K -= (now_score-key+F[i]-1) // F[i]
            if now_K < 0:
                return False
    return True


input = sys.stdin.readline

priority_que = []
N, K = map(int, input().split())
A = sorted(map(int, input().strip().split()))
F = sorted(map(int, input().strip().split()))[::-1]
score = [A[i]*F[i] for i in range(N)]
if sum(A) <= K:
    print("0")
    exit()


left = -1
right = max(score)
while right - left > 1:
    mid = (left+right) // 2
    can_eat = can_eat_with_score(mid)
    # print(mid, can_eat)
    if can_eat:
        right = mid
    else:
        left = mid
print(left+1)

Submission status: Time Limit Exceeded

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)
N, K =LI()
A = LI()
F = LI()
A.sort(reverse=True)
F.sort()

xupper = max(A)*max(F)
xlower = int(0)
xcandi = xupper//2

sumA = sum(A)

while (True):
#    print(xlower,xupper, xcandi)
    k = int(0)
    for i in range(N):
        k += max((A[i]*F[i]-xcandi+(F[i]-1))//F[i],0)
#    print(k)

    if k>K:
        xlower = xcandi
        xcandi = ((xcandi + xupper) // 2)+1
    else:
        if xupper-xlower<=1:
            ans = xcandi
            break
        else:
            xupper = xcandi
            xcandi = (xcandi + xlower) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def check(n, k , a, f, x):
    training_cnt = 0
    for i in range(n):
        t = x // f[i]  #a[i]をこれ以下にしたい。
        d = a[i] - t
        if d > 0:
            training_cnt += d
        if training_cnt > k:
            return False
    else:
        return True

def main():
    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)

    if check(N, K, A, F, 0):
        print(0)
        return


    left = 0
    right = 10 ** 12

    while left + 1 < right:
        mid = (left + right) // 2
        if check(N, K, A, F, mid):
            right = mid
        else:
            left = mid

    print(right)

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()))
f.sort()
a.sort()
a.reverse()
l=0
r=10**12+1
import math
while r-l>1:
	mid=(l+r)/2
	cnt=0
	for i in range(n):
		if a[i]*f[i]>mid:
			cnt+=a[i]-mid//f[i]
	if cnt<=k:
		r=mid
	else:
		l=mid
print(int(r))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

import math
import sys

n,k = map(int,input().split())
al = list(map(int,input().split()))
fl = list(map(int,input().split()))

al.sort()
fl.sort(reverse=True)

ub = max([a*f for a,f in zip(al, fl)])
lb = 0

while True:
    if ub == lb:
        print(lb)
        sys.exit()
    p = 0
    t = (ub + lb) // 2
    for a, f in zip(al, fl):
        p += max(a - t // f, 0)
    if p <= k:
        ub = t
    else:
        lb = t + 1

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

# 二分探索 #
def nibutan(): # MAX(A*F) ans
    left = -1
    ans = num
    while left+1 != ans:
        middle = (left+ans)//2
        if judge(middle):
            ans = middle
        else:
            left = middle
    return ans

N, K = IL()
a = IL()
f = IL()
a.sort()
f.sort(reverse=True)
num = 0
for i in range(N):
  num = max(num, a[i]*f[i])

print(nibutan())

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

import math
import sys

n,k = map(int,input().split())
al = list(map(int,input().split()))
fl = list(map(int,input().split()))

al.sort()
fl.sort(reverse=True)

ub = max([a*f for a,f in zip(al, fl)])
lb = 0

while True:
    if ub == lb:
        print(lb)
        sys.exit()
    p = 0
    t = int((ub + lb) / 2)
    for a, f in zip(al, fl):
        p += max(math.ceil(a - t / f), 0)
    if p <= k:
        ub = t
    else:
        lb = t + 1

Submission status: Time Limit Exceeded

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

B = [A[i] *F[i] for i in range(0,N)]
d = max(B)

def nex(x):
    count = 0
    for i in range(0,N):
        if x < B[i]:
            count += A[i] - int(x/F[i])
    return count

def target(l,r):
    if r - l == 1:
        if nex(l) <= K:
            return l
        else:
            return r
    elif nex(int((l+r)/2)) <= K:
         return target(l,int((l+r)/2))
    else:
        return target(int((l+r)/2),r)
    
ans = target(0,d)
print(ans)

Submission status: Time Limit Exceeded

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

B = [A[i] *F[i] for i in range(0,N)]
d = max(B)

def nex(x):
    count = 0
    for i in range(0,N):
        if x < B[i]:
            count += A[i] - int(x/F[i])
    return count

def target(l,r):
    if r - l == 1 and nex(l) <= K:
        return l
    elif r - l == 1 and nex(l) > K:
        return r
    elif nex(int((l+r)/2)) <= K:
         return target(l,int((l+r)/2))
    elif nex(int((l+r)/2)) > K:
        return target(int((l+r)/2),r)
    
ans = target(0,d)
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()  #从小到大
F.sort(reverse=True)  #从大到小

def isOk(x):
    cost = 0
    for a, f in zip(A,F):
        eatable = x//f
        if eatable >= a:
            continue
        cost += a - eatable
        if cost > k:
          return False
    return True

left = 0
right = A[-1] * F[0] + 1
while left < right:
    # mid = int(left + (right-left)//2)
    mid = (left+right)//2
    if isOk(mid):
        right = mid
    else:
        left = mid + 1
print(left)

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 isOk(x):
    cost = 0
    for a, f in zip(A,F):
        eatable = x//f
        if eatable >= a:
            continue
        cost += a - eatable
        if cost > k:
          return False
    return True

left = -1
right = A[-1] * F[0]
while left+1 < right:
    # mid = int(left + (right-left)//2)
    mid = (left+right)//2
    if isOk(mid):
        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()))
A.sort()
F.sort(reverse=True)

def isOk(x):
    cost = 0
    for a, f in zip(A,F):
        eatable = x//f
        if eatable >= a:
            continue
        cost += a - eatable
    if cost <= k:
        return True
    return False

left = -1
right = A[-1] * F[0]
while left+1 < right:
    # mid = int(left + (right-left)//2)
    mid = (left+right)//2
    if isOk(mid):
        right = mid
    else:
        left = mid
print(right)

Submission status: Time Limit Exceeded

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


left = -1
right = A[-1] * F[0]
while left+1 < right:
    mid = (left+right)//2
    cost = sum(A-np.minimum(A,mid//F))
    if cost <= k:
        right = mid
    else:
        left = mid
print(right)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline  #危険！基本オフにしろ！

def main():
    n,k=map(int,input().split())
    a=sorted(map(int,input().split()))
    b=sorted(map(int,input().split()),reverse=1)
    #print(a,b)
    ok=max(a)*max(b)
    ng=-1
    
    
            
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if sum(a[i]-mid//b[i]for i in range(n) if a[i]*b[i]>mid)<=k:
            ok=mid
        else:
            ng=mid
    print(ok)

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=sorted(map(int,input().split()))
    b=sorted(map(int,input().split()),reverse=1)
    #print(a,b)
    ok=max(a)*max(b)
    ng=-1
    
    def check(a,b,mid,k):
        if sum(a[i]-mid//b[i]for i in range(n) if a[i]*b[i]>mid)<=k:
            return 1
        else:
            return 0
            
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if check(a,b,mid,k):
            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=list(map(int,input().split()))
f=list(map(int,input().split()))
a=sorted(a)
f=sorted(f,reverse=True)
 
l=-1
r=max(a)*max(f)
def ok():
    s=0
    for i in range(n):
        s+=max(0,int(int(a[i])-int(c/f[i])))
    return s<=k
 
while(l+1<r):
    c=int((l+r)/2)
    if ok():
        r=c
    else:
        l=c
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=sorted(a)
f=sorted(f,reverse=True)

l=-1
r=10**12
def ok():
    s=0
    for i in range(n):
        s+=max(0,int(int(a[i])-int(c/f[i])))
    return s<=k

while(l+1<r):
    c=int((l+r)/2)
    if ok():
        r=c
    else:
        l=c
print(r)

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)

def isOk(x):
    cost = 0
    for a, f in zip(A,F):
        eatable = x//f
        if eatable >= a:
            continue
        cost += a - eatable
    if cost <= k:
        return True
    return False

left = -1
right = A[-1] * F[0]
while left+1 < right:
    mid = (left+right)//2
    if isOk(mid):
        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=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
l=0
r=10**12
x=(r+l)//2
a=np.array(a)
f=np.array(f)
def check(x):
    p=np.sum(np.maximum(np.array([0]*n),a-x//f))
    if p>k:
        return False
    else:
        return True
while l<r:
    if check(x):
        r=x
        x=(r+l)//2
    else:
        l=x
        x=(r+l)//2
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)

def isOk(x):
    cost = 0
    for a, f in zip(A,F):
        eatable = x//f
        if eatable >= a:
            continue
        cost += a - eatable
    if cost <= k:
        return True
    return False

left = -1
right = A[-1] * F[0]
while left+1 < right:
    mid = int(left + (right-left)//2)
    if isOk(mid):
        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()))
A.sort()
F.sort(reverse=True)

def isOk(x):
    cost = 0
    for i in range(n):
        eatable = x//F[i]
        if eatable >= A[i]:
            continue
        cost += A[i] - eatable
    if cost <= k:
        return True
    return False

left = 0
# right = 1e12
right = A[-1] * F[0]
while left+1 < right:
    # mid = int(left + (right-left)//2)
    mid = (left+right)//2
    if isOk(mid):
        right = mid
    else:
        left = mid
if sum(A) <= k:
    right = 0
print(right)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
import heapq as hq

a = sorted(list(map(int,input().split())))
f = sorted(list(map(int,input().split())))[::-1]

h = []
for i in range(n):
  hq.heappush(h,(-1*a[i]*f[i],i))

for i in range(k):
  if h[0][0] == 0: break
  t = hq.heappop(h)
  a[t[1]] -= 1
  hq.heappush(h,(-1*a[t[1]]*f[t[1]],t[1]))
                  
  
"""
print(h)
print(a)
print(f)
"""
print(-1*h[0][0])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import math
def solve():
  n,k = (int(i) for i in input().split())
  a = sorted(list(int(i) for i in input().split()))
  f = sorted(list(int(i) for i in input().split()),reverse = True)
  if sum(a) <= k:
    print(0)
    exit()
  
  ng = 0
  ok = 10**15

  while ok-ng >1 :
    next = (ok+ng)//2
    #a*fの値がnext以下になるか判定する
    tmpk = k
    for i in range(n):
      ta = a[i]
      tf = f[i]
      if ta*tf > next:
        tmpk -= math.ceil((ta*tf-next)/tf)
    if tmpk < 0:
       ng = next
    else:
       ok = next
  print(ok)
    
solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a = np.sort(np.array(a))[::-1]
f = np.sort(np.array(f))

if sum(a) <= k:
    print(0)
else:
    l = 0
    r = a[0]*f[-1]
    while l <= r:
        lr = (l+r)//2
        s = sum(np.clip(a-lr//f,0,None))
        if s > k:
            l = lr + 1
        else:
            r = lr - 1
    print(l)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import bisect

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

F = sorted(F, reverse = True)
A = sorted(A)
flg = 0
lst = []

for i in range(N):
	if A[i] == 0 or F[i] == 0:
		break
	else:
		lst.insert(bisect.bisect_left(lst, [A[i] * F[i], F[i]]),[A[i] * F[i], F[i]]) 
		# heapq.heappush(heap, [- A[i] * F[i], F[i]])
		
for i in range(K):
	popped = lst.pop(-1)
	popped[0] -= popped[1]
	lst.insert(bisect.bisect_left(lst, popped), popped)

print(lst[-1][0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a  = np.sort(np.array(a))
f = np.sort(np.array(f))[::-1]

l ,r = 0, 10 ** 12
x = 0
while l <= r:
	x = (l + r) // 2
	if np.clip(a - f // x, 0, None).sum() <= k:
		l += 1
	else:
		r -= 1
print(l)

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

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

def binary_search(min_f, max_f):
	if min_f == max_f:
		return min_f

	mid_f = min_f + (max_f - min_f)//2
	tmp = 0
	for i in range(N):
		tmp += max(0,A[i] - mid_f // F[i])
	
	if tmp <= K:
		return binary_search(min_f, mid_f)
	else:
		return binary_search(mid_f+1, max_f)

print(binary_search(0, max_f))

Submission status: Time Limit Exceeded

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


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

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

    l = -1
    r = 10 ** 13

    def test(x):
        cnt = 0
        for ae, fe in zip(a, f):
            cnt += max(0, ae - x // fe)

        return cnt <= k

    while l + 1 < r:
        m = (l + r) // 2
        if test(m):
            r = m
        else:
            l = m

    ans = r
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from heapq import heapify, heappop, heappush

N, K = [int(i) for i in input().split()]
A = [-int(i) for i in input().split()]
F = [int(i) for i in input().split()]

A.sort()
F.sort()
S = [(a*f, f) for a, f in zip(A, F)]
S.sort()
heapify(S)

for _ in range(K):
    s = heappop(S)
    if s[0] > 0:
        break
    else:
        heappush(S, (s[0]+s[1], s[1]))
print(-S[0][0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
INF = float('inf')

def sol():
    _, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))

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

    def isOk(t):
        cnt = 0
        for a, f in zip(A, F):
            n = t // f
            if a > n:
                cnt += a - n

        if cnt > K:
            return False
        else:
            return True

    ng = -1
    ok = max((a * f for a, f in zip(A, F))) + 1

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

sol()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
INF = float('inf')

def sol():
    _, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))

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

    def isOk(t):
        cnt = sum((max(0, a - t // f) for a, f in zip(A, F)))

        if cnt > K:
            return False
        else:
            return True

    ng = -1
    ok = max((a * f for a, f in zip(A, F))) + 1

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

sol()

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
lis.sort(reverse=True)
li.sort()
hi = 10 ** 12
low = 0
while hi > low+1:
    mid = (hi + low)//2
    cnt = 0
    for i in range(n):
        cnt += max(0,lis[i]-mid//li[i])
    if cnt <= k:
        hi = mid
    else:
        low = mid
    ans1 = low
    ans2 = hi
cnt = 0
for i in range(n):
    cnt += max(0,lis[i]-ans1//li[i])
if cnt <= k:
    print(ans1)
else:
    print(ans2)

Submission status: Time Limit Exceeded

Solution code:
# ABC144E - Gluttony
def binary_search(upper_lim: int) -> int:
    ok, ng = upper_lim, -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


def check(x: int) -> bool:
    cost = sum(a - x // f for a, f in zip(A, F) if a * f > x)
    return cost <= K


def main():
    global K, A, F
    N, K, *AF = map(int, open(0).read().split())
    A, F = AF[:N], AF[N:]
    A.sort(), F.sort(reverse=1)
    ans = binary_search(A[-1] * F[0] + 1)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import heapq

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
T = [[- A[i] * F[i], A[i]] for i in range(N)]
heapq.heapify(T)

for _ in range(K):
    t, a = heapq.heappop(T)
    if t < 0:
        heapq.heappush(T, [(t // a) * (a - 1), a - 1])
    else:
        heapq.heappush(T, [0, 0])
        break

print(- heapq.heappop(T)[0])

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def bisect_left(f, x, hi):
  lo = 0
  while lo < hi:
    mid = math.ceil((hi + lo) / 2)
    score = f * mid
    if x < score:
      hi = mid - 1
    else:
      lo = mid
  return lo
  
def main():
  
  n, k = map(int, input().split())  
  a_list = [int(_) for _ in sys.stdin.readline().split()]
  f_list = [int(_) for _ in sys.stdin.readline().split()]
              
  a_list.sort()
  f_list.sort(reverse=True)

  if sum(a_list) <= k:
    print(0)
  else:
    x = 1
    while True:
      num_training = 0
      for i in range(n):
        num_training += max(0, a_list[i] - bisect_left(f_list[i], x, k))
        if num_training > k:
          break
      else:
        print(x)
        break
      x += 1

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def bisect_left(f, x, hi):
  lo = 0
  while lo < hi:
    mid = math.ceil((hi + lo) / 2)
    score = f * mid
    if x < score:
      hi = mid - 1
    else:
      lo = mid
  return lo
  
def main():
  
  n, k = map(int, input().split())  
  a_list = [int(_) for _ in sys.stdin.readline().split()]
  f_list = [int(_) for _ in sys.stdin.readline().split()]
              
  a_list.sort()
  f_list.sort(reverse=True)

  if sum(a_list) <= k:
    print(0)
  else:
    x = 1
    while True:
      num_training = 0
      for i in range(n):
        num_training += max(0, a_list[i] - bisect_left(f_list[i], x, k) )
      if num_training <= k:
        print(x)
        break
      x += 1

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def bisect_left(f, x, hi):
  lo = 0
  while lo < hi:
    mid = math.ceil((hi + lo) / 2)
    score = f * mid
    if x < score:
      hi = mid - 1
    else:
      lo = mid
  return lo
  
def main():
  
  n, k = map(int, input().split())  
  a_list = list(map(int, sys.stdin.readline().split()))
  f_list = list(map(int, sys.stdin.readline().split()))
              
  a_list.sort()
  f_list.sort(reverse=True)

  if sum(a_list) <= k:
    print(0)
  else:
    x = 1
    while True:
      num_training = 0
      for i in range(n):
        # print(max(0, a_list[i] - bisect_left(f_list[i], x, k) ) )
        num_training += max(0, a_list[i] - bisect_left(f_list[i], x, k) )
      # print('x', x)
      # print('number of training', num_training)
      if num_training <= k:
        print(x)
        break
      x += 1

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)

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

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

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)

M = 0
for i in range(N):
    M=max(F[i]*A[i],M)

def judge(n):
    score = 0
    for i in range(N):
        score += max(A[i] - n//F[i],0)
    return score<=K

def bisect(l,r):
    while r-l>1:
        if judge((l+r)//2):
            r = (l+r)//2
        else:
            l = (l+r)//2
    return r

if judge(0):
    print(0)
else:
    print(bisect(0,M))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n,k,*a=map(int,open(0).read().split())
    *z,=zip(sorted(a[:n]),sorted(a[n:],reverse=1))
    ok=10**12
    ng=-1
    while ok-ng>1:
        mid=(ok+ng)//2
        l=k
        for b,g in z:
            if b*g>mid:l-=b-mid//g
        if l<0:ng=mid
        else:ok=mid
    print(ok)
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n,k,*a=map(int,open(0).read().split())
    a,f=sorted(a[:n]),sorted(a[n:])[::-1]
    ok=10**12
    ng=-1
    while ok-ng>1:
        mid=(ok+ng)//2
        l=k
        for b,g in zip(a,f):
            if b*g>mid:l-=b-mid//g
        if l<0:ng=mid
        else:ok=mid
    print(ok)
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)

maxaf=1000000000000

def solve(x):
	total=0
	for i in range(n):
		total+=max(0,a[i]-x//f[i])
	return total<=k

#xの範囲 ngは実現が難しい方
ok=maxaf
ng=-1

while 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 = list(map(int,input().split()))
F = list(map(int,input().split()))

A_sort = sorted(A)
F_sort = sorted(F,reverse=True)

l = -1
r = 0
for i in range(N):
    r = max(r,A_sort[i]*F_sort[i])

def judge(c):
    s = 0
    for i in range(N):
        s += max(A_sort[i]-c//F_sort[i],0)
    return s <= K

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

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(reverse = True)
    F.sort()

    if K >= sum(A): return 0

    B = [A[i] * F[i] for i in range(N)]
    l, r = 0, max(B)
    ans = float('inf')
    while l <= r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i] - m > 0:
                count += (B[i] - m) // F[i]
                if (B[i] - m) % F[i] != 0:
                    count += 1
        if count <= K:
            ans = min(ans, m)
            if r == m-1: break
            r = m-1
        else:
            if l == m+1: break
            l = m+1
        # print(l, r)
    return ans

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

Submission status: Time Limit Exceeded

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

A_sort = sorted(A)
F_sort = sorted(F,reverse=True)

l = -1
r = 0
for i in range(N):
    r = max(r,A_sort[i]*F_sort[i])

def judge(c):
    s = 0
    for i in range(N):
        s += max(A_sort[i]-c//F_sort[i],0)
    return s <= K

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