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

ss = [[] for i in range(2)]
for i in range(2):
    ss[i] = list(map(int,input().split()))


A = ss[0]
F = ss[1]
A.sort()
F.sort()
F.reverse()

left = -1
right = max([(A[j] * F[j]) for j in range(n)])

while (right - left) > 1:
    b = [[] for i in range(n)]
    s = left + ((right - left) // 2)
    for i in range(n):
        b[i] = min(s//F[i],A[i])
    if (sum(A) - sum(b)) <= k:
        right = s 
    else:
        left = s 

print(right)

Submission status: Time Limit Exceeded

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

    l = 0
    r = A[-1] * F[0]
    while r != l:
        t = l + (r - l) // 2
        if K >= sum(a - t // f for a, f in zip(A, F) if a * f > t):
            r = t
        else:
            l = t + 1
    print(r)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))
    F = sorted(map(int, input().split()), reverse=True)
    def helper(t):
        k = K
        for a, f in zip(A, F):
            if a * f <= t:
                continue
            m = t // f
            k -= (a - m)
            if k < 0:
                return False
        return True

    l = 0
    r = A[-1] * F[0]
    while r != l:
        m = l + (r - l) // 2
        if helper(m):
            r = m
        else:
            l = m + 1
    print(r)


if __name__ == '__main__':
    main()

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


def search(left, right):
    if left == right:
        return left
    mid = (left + right) // 2
    total_fix = 0
    # for i in range(N):
    #     # (Ai - fix) * Fi <= mid
    #     # Ai - fix <= mid / Fi
    #     # Ai - fix <= mid // Fi
    #     # Ai - mid // Fi <= fix
    #     total_fix += max(0, A[i] - mid // F[i])

    # if total_fix == K:
    #     return total_fix
    B = (A - mid // F)
    # print(B)
    B = np.array(list(filter(lambda x: x > 0, B)))
    total_fix = np.sum(B)
    # print(tota)
    if total_fix > K:
        # mid -> not enough. More training needed
        return search(min(mid + 1, int(1e12)), right)
    else:
        # mid -> K training is enough.
        # but we may decrease `mid` more.
        return search(left, mid)


ans = search(0, int(1e12))
print(ans)

Submission status: Time Limit Exceeded

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


def search(left, right):
    if left == right:
        return left
    mid = (left + right) // 2
    total_fix = 0
    for i in range(N):
        # (Ai - fix) * Fi <= mid
        # Ai - fix <= mid / Fi
        # Ai - fix <= mid // Fi
        # Ai - mid // Fi <= fix
        total_fix += max(0, A[i] - mid // F[i])
        if total_fix > K:
            break

    # if total_fix == K:
    #     return total_fix

    if total_fix > K:
        # mid -> not enough. More training needed
        return search(min(mid + 1, int(1e12)), right)
    else:
        # mid -> K training is enough.
        # but we may decrease `mid` more.
        return search(left, mid)


ans = search(0, int(1e12))
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 search(left, right):
    if left == right:
        return left
    mid = (left + right) // 2
    total_fix = 0
    for i in range(N):
        # (Ai - fix) * Fi <= mid
        # Ai - fix <= mid / Fi
        # Ai - fix <= mid // Fi
        # Ai - mid // Fi <= fix
        total_fix += max(0, A[i] - mid // F[i])

    # if total_fix == K:
    #     return total_fix

    if total_fix > K:
        # mid -> not enough. More training needed
        return search(min(mid + 1, int(1e12)), right)
    else:
        # mid -> K training is enough.
        # but we may decrease `mid` more.
        return search(left, mid)


ans = search(0, int(1e12))
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()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
l=0
r=10**12
x=(r+l)//2
def check(x):
    p=0
    for i in range(n):
        if x//f[i]<a[i]:
            p+=a[i]-x//f[i]
            if p>k:
                return False
    if p>k:
        return False
    else:
        return True
while l+1<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:
import numpy as np


def solve():
    N, K = map(int, input().split())
    a_l = np.array(input().split(), int)
    b_l = np.array(input().split(), int)
    a_l.sort()
    b_l.sort()
    b_l = b_l[::-1]

    sum_a = sum(a_l)
    left, right = -1, 10**12
    while left + 1 < right:
        mid = (left + right) // 2
        if sum_a - sum(np.minimum(a_l, mid//b_l)) <= K:
            right = mid
        else:
            left = mid

    print(right)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k=map(int,input().split())
a=np.array(sorted(list(map(int,input().split()))))
f=np.array(sorted(list(map(int,input().split())),reverse=True))
def l(x):
  l=0
  for i in range(n):
    b=int(x/f[i])
    m=a[i]-b
    if m:
      l+=m
  return(int(l))
x=0
while l(x)>k:
  x+=1

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()))
all_0 = [0 for i in range(N)]
A.sort()
F.sort()
F.reverse()
MUL = [A[i]*F[i] for i in range(N)]

def max_MUL():
    max_MUL = -1
    index = -1
    for i in range(N):
        if max_MUL<MUL[i]:
            max_MUL = MUL[i]
            index = i
        elif max_MUL==MUL[i]:
            if F[index]<F[i]:
                index = i
    return index
def Gluttony(K):
    if A == all_0:
        return 0
    while K>0:
        index = max_MUL()
        A[index]-=1
        MUL[index]=A[index]*F[index]
        K-=1
        if A == all_0:
            return 0
    return MUL[max_MUL()]

print(Gluttony(K))

Submission status: Time Limit Exceeded

Solution code:
import sys
import queue
bbn=1000000007
	
#+++++
		
def main():
	n, k = map(int, input().split())
	al=list(map(int, input().split()))
	fl=list(map(int, input().split()))
	
	qq=queue.PriorityQueue()
	
	al.sort(reverse=True)
	fl.sort()
	for a,f in zip(al,fl):
		qq.put((-a*f, a, f))
	
	#while not qq.empty():
	#	a=qq.get()
	#	pa(a)
	
	for i in range(k):
		c,a,f=qq.get()
		if a == 0:
			return 0
		an=a-1
		qq.put((-an*f, an, f))		
		
	c,a,f = qq.get()
	print(-c)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys
 
def jeat(a, f, x, K):
    N = 0
    for i in range(len(a)):
        if a[i]*f[i] > x:
            N += a[i] - x // f[i]
    if N > K:
        return False
    if N <= K:
        return True
 
N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
if K >= sum(A):
    print(0)
    sys.exit()
A.sort()
F.sort(reverse = True)
a = 0
b = 10**18
while (True):
    z = (a+b)//2
    if jeat(A,F,z,K) == True:
        if jeat(A,F,z-1,K) == False:
            break
        b = z-1
    else:
        if jeat(A,F,z+1,K) == True:
            z += 1
            break
        a = z+1
 
print(z)

Submission status: Time Limit Exceeded

Solution code:
import sys

def jeat(a, f, x, K):
    N = 0
    for i in range(len(a)):
        if a[i]*f[i] > x:
            N += a[i] - x // f[i]
    if N > K:
        return False
    if N <= K:
        return True

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
if K >= sum(A):
    print(0)
    sys.exit()
A.sort()
F.sort(reverse = True)
a = 0
b = 10**18
while (True):
    z = (a+b)//2
    if jeat(A,F,z,K) == True:
        if jeat(A,F,z-1,K) == False:
            break
        b = z-1
    else:
        if jeat(A,F,z+1,K) == True:
            z += 1
            break
        a = z+1

print(z)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil

input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    A = sorted(list(map(int, input().split())), reverse=True)
    F = sorted(list(map(int, input().split())))
    
    l, r = 0, A[0] * F[-1]
    
    while l < r:
        mid = (l+r) // 2
        k = K
        
        for a, f in zip(A, F):
            if a * f <= mid: continue
        
            x = ceil(-mid/f + a)
            k -= x
            if k < 0: break
        
        if k < 0: l = mid+1
        else: r = mid
    
    print(r)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import heapq
import sys

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

a = [[-a[i]*f[i],f[i]] for i in range(n)]
heapq.heapify(a)

for i in range(k):
  tmp = heapq.heappop(a)
  if tmp[0] != 0:
    tmp[0] += tmp[1]
  heapq.heappush(a,tmp)

ans = sys.maxsize
for i in range(n):
  tmp = heapq.heappop(a)
  ans = min(tmp[0], ans)

print(-ans)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
af = [a[i]*f[i] for i in range(n)]
lower = 0
upper = max(af)
prev = 0
now = upper // 2
while now != prev:
  count = 0
  for i in range(n):
    if a[i]*f[i] > now:
      count += a[i] - now // f[i]
  if count <= k:
    upper = now
  else:
    lower = now
  prev = now
  now = (lower + upper) // 2

print(upper)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)

def how_many_K(A,F,T,K):
    """
    Returns whether the number of training sessions needed for group A with foods F to have a score equal to T is less than K
    """
    num_trains = 0
    for i in range(len(A)):
        a = A[i]
        f = F[i]
        num_trains += max(0, a-T//f)

    if num_trains > K:
        return False
    else:
        return True

maxT = np.max(A*F)
# use binary search to find lowest possible T
left = -1
right = maxT
while left+1< right:
    mid = (left+right)//2
    if how_many_K(A,F,mid,K):
        right  = mid
    else:
        left = mid
print(right)

Submission status: Time Limit Exceeded

Solution code:
inputs = list(map(int, input().split()))
an = list(map(int, input().split()))
fn = list(map(int, input().split()))

n = inputs[0]
k = inputs[1]

an.sort()
fn.sort(reverse=True)
muln = [an[j]*fn[j] for j in range(n)]
costMax = 0
for i in range(n):
  costMax = max(costMax, an[i]*fn[i])

left = 0
right = costMax

while (right-left>1):
  mid = int((left+right)/2)

  total = 0
  for i in range(n):
    total += max(0, an[i]-int(mid/fn[i]))

  if total <= k:
    right = mid
  elif total > k:
    left = mid

if left == 0:
  print("0")
else:
  print(right)

Submission status: Time Limit Exceeded

Solution code:
inputs = list(map(int, input().split()))
an = list(map(int, input().split()))
fn = list(map(int, input().split()))

n = inputs[0]
k = inputs[1]

an.sort()
fn.sort(reverse=True)

left = 0
right = 10**18

while (right-left>1):
  mid = int((left+right)/2)

  total = 0
  for i in range(n):
    total += max(0, an[i]-int(mid/fn[i]))

  if total <= k:
    right = mid
  elif total > k:
    left = mid

if left == 0:
  print("0")
else:
  print(right)

Submission status: Time Limit Exceeded

Solution code:
inputs = list(map(int, input().split()))
an = list(map(int, input().split()))
fn = list(map(int, input().split()))

n = inputs[0]
k = inputs[1]

an.sort()
fn.sort(reverse=True)
muln = [an[j]*fn[j] for j in range(n)]

left = 0
right = 10**18

while (right-left>1):
  mid = int((left+right)/2)

  total = sum([an[i]-int(mid/fn[i]) if mid < muln[i] else 0 for i in range(n)])

  if total <= k:
    right = mid
  elif total > k:
    left = mid

if left == 0:
  print("0")
else:
  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=sorted(a)[::-1]
f=sorted(f)

ok=10**18
ng=-1

import math
def isOK(val,arr,farr,k):
  s=0
  for i in range(len(arr)):
    s+=max(math.ceil(a[i]-val/f[i]),0)
  return s<=k
  
while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOK(mid,a,f,k):
    ok=mid
  else:
    ng=mid
    
print(ok)

Submission status: Time Limit Exceeded

Solution code:
inputs = list(map(int, input().split()))
an = list(map(int, input().split()))
fn = list(map(int, input().split()))

n = inputs[0]
k = inputs[1]

an.sort()
fn.sort(reverse=True)
muln = [an[j]*fn[j] for j in range(n)]

for i in range(k):
  index = muln.index(max(muln))
  if an[index] == 0:
    break
  an[index] = an[index] - 1
  muln[index] = an[index] * fn[index]

muln = [an[i]*fn[i] for i in range(n)]
print(max(muln))

Submission status: Time Limit Exceeded

Solution code:
inputs = list(map(int, input().split()))
an = list(map(int, input().split()))
fn = list(map(int, input().split()))

n = inputs[0]
k = inputs[1]

an.sort()
fn.sort(reverse=True)

for i in range(k):
  muln = [an[j]*fn[j] for j in range(n)]
  index = muln.index(max(muln))
  if an[index] == 0:
    break
  an[index] = an[index] - 1

muln = [an[i]*fn[i] for i in range(n)]
print(max(muln))

Submission status: Time Limit Exceeded

Solution code:
inputs = list(map(int, input().split()))
an = list(map(int, input().split()))
fn = list(map(int, input().split()))

n = inputs[0]
k = inputs[1]

for i in range(k):
  an.sort()
  fn.sort(reverse=True)

  muln = [an[i]*fn[i] for i in range(n)]
  if max(muln) == 0:
    break
  index = muln.index(max(muln))
  an[index] = an[index] - 1

muln = [an[i]*fn[i] for i in range(n)]
print(max(muln))

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)
ans = [i*j for i,j in zip(a,f)]
for i in range(k):
    max_ind = ans.index(max(ans))
    a[max_ind] -= 1
    a.sort()
    ans = [i*j for i,j in zip(a,f)]
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
### D - Glutony ###
# TLE
# defでやると遅いので、

N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
F = list(map(int, input().split())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()

range_max = A[0] * F[-1] + 1
range_min = 0

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(range_min, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

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())) # 食べにくさ
 
import math
import numpy as np
 
A.sort(reverse = True)
F.sort()
 
arrA = np.array(A)
arrF = np.array(F)
 
range_max = max(arrA * arrF) + 1
range_min = max(min((arrA - K) * arrF), 0)
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(range_min, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

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())) # 食べにくさ
 
import math
import numpy
 
A.sort(reverse = True)
F.sort()
 
range_max = max([i*j for i,j in zip(A,F)]) + 1
range_min = max(min([(i-K)*j for i,j in zip(A,F)]), 0)
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(range_min, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

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())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()
 
range_max = max([i*j for i,j in zip(A,F)]) + 1
range_min = max(min([(i-K)*j for i,j in zip(A,F)]), 0)
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(range_min, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

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())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()
 
range_max = max([i*j for i,j in zip(A,F)]) + 1
range_min = max(min([(i-K)*j for i,j in zip(A,F)]), 0)

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K

my_range = range(0, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

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())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()
 
range_max = max([i*j for i,j in zip(A,F)]) + 1
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(0, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

Submission status: Time Limit Exceeded

Solution code:
# Gluttony
# AC 10/35 TLE 25/35

N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
F = list(map(int, input().split())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(0, 10**18)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

Submission status: Time Limit Exceeded

Solution code:
# Gluttony
# AC 10/35 TLE 25/35

N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
F = list(map(int, input().split())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(0, 10**18)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)

node(my_range)

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())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(0, 10**18)
 
def node(lst):
    if len(lst) % 2 == 0:
        mid_idx = int(len(lst)/2)
    else:
        mid_idx = int(math.floor(len(lst)/2))
 
    if len(lst) == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
 
node(my_range)

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, ng = a[-1]*f[0], -1
while ok-ng > 1:
	x = (ok+ng)//2
	tmp = 0
	for i in range(n):
		tmp += max(0, a[i] - x//f[i])
	if tmp > k:
		ng = x
	else:
		ok = x
print(ok)

Submission status: Time Limit Exceeded

Solution code:
# for submit
def Gluttony():

    N, K = map(int, input().split())
    A = list(map(int, input().split())) # 消化コスト
    B = list(map(int, input().split())) # 食べにくさ

    A.sort()
    B.sort(reverse = True) # 

    glut = [i*j for i, j in zip(A,B)]
    
    for disused in range(0, K):
        idx = glut.index(max(glut))
        A[idx] = A[idx] - 1
        glut[idx] = A[idx]*B[idx]
        #print(glut)

    print(max(glut))

Gluttony()

Submission status: Time Limit Exceeded

Solution code:
# for submit
def Gluttony():

    N, K = map(int, input().split())
    A = list(map(int, input().split())) # 消化コスト
    B = list(map(int, input().split())) # 食べにくさ

    A.sort()
    B.sort(reverse = True) # 

    for disused in range(0, K+1):
        glut = [i*j for i, j in zip(A,B)]
        idx = glut.index(max(glut))
        A[idx] = A[idx] - 1

    print(max(glut))

Gluttony()

Submission status: Time Limit Exceeded

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()
    f = list(map(int, readline().split()))
    f.sort(reverse=True)

    cor_v = 10 ** 22
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            if a[i] * f[i] >= bin_v:
                cost += ((a[i] * f[i]) - bin_v + f[i] - 1) // f[i]
            if cost > k:
                break
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

## Aは昇順Fは降順に並び替える
A.sort()
F.sort(reverse=True)

A=np.array(A)
F=np.array(F)

## 成績(A × F)の目標をxにしたときに何回修行が必要かを求める関数
def target(x):
    train_count = 0
    for i in range(N):
        a = A[i]
        targ_a = x // F[i] # 目標を達成した時の消費コストA
        if targ_a < a:
            train_count += a - targ_a
    return train_count <= K

## 二分探索(リストを半分ずつ削って達成可能な目標を探す)
left = -1                            # 一番左
right = A[-1] * F[0]                 # 一番右(Aの最大値 × Fの最大値)
while right > left+1:                # 一番右が一番左より大きい間（一致したら終了）
    middle = (left + right) // 2     # 真ん中
    if target(middle):               # 目標を真ん中にして達成可能なら
        right = middle               # 一番右を真ん中にする（残りの右側は無駄に時間かかってるから切り捨てる）
    else:                            # 達成できないなら(K回を超えてしまうとき）
        left = middle                # 一番左を真ん中にする（残りの左側は達成不可だから切り捨てる）
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 target(x):
    train_count = 0
    for i in range(N):
        a = A[i]
        targ_a = x // F[i] 
        if targ_a < a:
            train_count += a - targ_a
    return train_count <= K

left = -1                            
right = A[-1] * F[0]                 
while right > left+1:                
    middle = (left + right) // 2     
    if target(middle):               
        right = middle               
    else:              
        left = middle 
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は昇順Fは降順に並び替える
A.sort()
F.sort(reverse=True)

## 成績(A × F)の目標をxにしたときに何回修行が必要かを求める関数
def target(x):
    train_count = 0
    for i in range(N):
        a = A[i]
        targ_a = x // F[i] # 目標を達成した時の消費コストA
        if targ_a < a:
            train_count += a - targ_a
    return train_count <= K

## 二分探索(リストを半分ずつ削って達成可能な目標を探す)
left = -1                            # 一番左
right = A[-1] * F[0]                 # 一番右(Aの最大値 × Fの最大値)
while right > left+1:                # 一番右が一番左より大きい間（一致したら終了）
    middle = (left + right) // 2     # 真ん中
    if target(middle):               # 目標を真ん中にして達成可能なら
        right = middle               # 一番右を真ん中にする（残りの右側は無駄に時間かかってるから切り捨てる）
    else:                            # 達成できないなら(K回を超えてしまうとき）
        left = middle                # 一番左を真ん中にする（残りの左側は達成不可だから切り捨てる）
print(right)

Submission status: Time Limit Exceeded

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

N, K = map(int, readline().split())
A = np.array(readline().split(),np.int64)
F = np.array(readline().split(),np.int64)

A.sort()
F.sort()
F=F[::-1]
 
new_list_a = np.array(A)
new_list_f = np.array(F)
 
for _ in range(K):
  time = new_list_f * new_list_a
  number_a = np.argmax(time)
  new_list_a[number_a] = new_list_a[number_a] - 1
  time = new_list_f * new_list_a
  
print(max(time))

Submission status: Time Limit Exceeded

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

N, K = map(int, readline().split())
A = np.array(readline().split(),np.int64)
F = np.array(readline().split(),np.int64)

A.sort()
F.sort()
F=F[::-1]
 
new_list_a = np.array(A)
new_list_f = np.array(F)
 
for i in range(K):
  time = new_list_f * new_list_a
  number_a = np.argmax(time)
  new_list_a[number_a] = new_list_a[number_a] - (i - (i - 1))
  time = new_list_f * new_list_a
  
print(max(time))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
 
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)
 
new_list_a = np.array(A)
new_list_f = np.array(F)
time = new_list_f * new_list_a
 
for i in range(K):
  number_a = np.argmax(time)
  new_list_a[number_a] = new_list_a[number_a] - (i - (i - 1))
  time = new_list_f * new_list_a
  
print(max(time))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
 
N, K = map(int, input().split())
new_list_a = sorted(list(map(int, input().split())), reverse=True)
new_list_f = sorted(list(map(int, input().split())))
 
new_list_a = np.array(new_list_a)
new_list_f = np.array(new_list_f)
time = new_list_f * new_list_a
 
for i in range(K):
  number_a = np.argmax(time)
  new_list_a[number_a] = new_list_a[number_a] - (i - (i - 1))
  time = new_list_f * new_list_a
  
print(max(time))

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)

l,u=-1,f[0]*a[-1]
while l+1<u:
  m=(l+u)//2
  s=0
  for i in range(n):
    s+= a[i]-m//f[i] if a[i]>m//f[i] else 0
  if s<=k:
    u=m
  else:
    l=m

print(u)