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: Wrong Answer

Solution code:
import numpy as np

def solve(n, k, aaa, fff):
  aaa = np.sort(aaa)
  fff = np.sort(fff)[::-1]
  
  l = 0
  r = 10**12
  while l<=r:
    m = (l+r)//2
    req = np.clip(aaa - m//fff, 0, None).sum()

    if req < k:
      r = m-1
    else:
      l = m+1

  return l


N, K = map(int,input().split())
aaa = np.array(list(map(int,input().split())))
fff = np.array(list(map(int,input().split())))

print(solve(N, K, aaa, fff))

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
A=list(map(int,input().split()))
F=sorted(list(map(int,input().split())),reverse=True)
result=[]
ok=A[N-1]*F[0]
ng=-1
while(ng+1<ok):
  c=(ng+ok)/2
  sum=0
  result =[]
  for i in range(N):
    sum += A[i] - c/F[i]
  if(sum<=K):
    ok=c
  else:
    ng=c

print(math.ceil(ok))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
F=map(int, sys.stdin.readline().split())
A.sort(reverse=True)
F.sort()

max_ans=10**12

def check(temp_ans):
    if temp_ans<0:
        return False
    k=0
    for a,f in zip(A,F):
        aa=temp_ans/f
        k+=(a-aa)
        if K<k:
            return False
    else:
        return True

h=max_ans
l=-1

while h-l!=1:
    m=(h+l)/2
    if check(m):
        h=m
    else:
        l=m

print h

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
F=map(int, sys.stdin.readline().split())
A.sort(reverse=True)
F.sort()

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

def check(temp_ans):
    if temp_ans<0:
        return False
    k=0
    for a,f in zip(A,F):
        aa=temp_ans/f
        k+=(a-aa)
        if K<k:
            return False
    else:
        return True

h=max_ans
l=-1

while h-l!=1:
    m=(h+l)/2
    if check(m):
        h=m
    else:
        l=m

print h

Submission status: Wrong Answer

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 = 10**6 * 10**6 #最大でかかる時間
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+1)//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 より
        sum_ax += ax
        '''
        if ax < An[i]:
            new_list[i] = ax
        else:
            new_list[i] = An[i]
        '''
    if sum_ax <=0 or min_time+1 == max_time: #An_s - sum_candisum_axdate == K or
        break
    elif An_s - sum_ax <= K:
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい

print(middle_time)

Submission status: Wrong Answer

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 = N**6 * N**6 #最大でかかる時間
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+1)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    new_list = init_list
    for i in range_n:
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            new_list[i] = ax
        else:
            new_list[i] = An[i]
    sum_candidate = sum(new_list)
    if sum_candidate <=0 or min_time+1 == max_time: #An_s - sum_candidate == K or
        break
    elif An_s - sum_candidate <= K:
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい

print(middle_time)

Submission status: Wrong Answer

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 = 10**6 * 10**6 #最大でかかる時間
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+1)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    new_list = init_list
    for i in range_n:
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            new_list[i] = ax
        else:
            new_list[i] = An[i]
    sum_candidate = sum(new_list)
    if sum_candidate <=0 or min_time+1 == max_time: #An_s - sum_candidate == K or
        break
    elif An_s - sum_candidate <= K:
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい

print(middle_time)

Submission status: Wrong Answer

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 = 10**6 * 10**6 #最大でかかる時間
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+1)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    new_list = init_list
    for i in range_n:
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            new_list[i] = ax
        else:
            new_list[i] = An[i]
    sum_candidate = sum(new_list)
    if sum_candidate <=0 : #An_s - sum_candidate == K or
        break
    elif An_s - sum_candidate <= K:
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい
    if min_time+1 == max_time:
        break

print(middle_time)

Submission status: Wrong Answer

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 = 10**6 * 10**6 #最大でかかる時間
middle_time = -1
while middle_time+1 != max_time:
    # max_time+1は max_time=0まで求めるため
    middle_time = (min_time + max_time+1)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    new_list = [0]*N
    for i in range(N):
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            new_list[i] = ax
        else:
            new_list[i] = An[i]
    sum_candidate = sum(new_list)
    if An_s - sum_candidate == K or sum_candidate <=0 :
        break
    elif An_s - sum_candidate < K:
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい
print(middle_time)

Submission status: Wrong Answer

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 = 10**6 * 10**6 #最大でかかる時間
middle_time = -1
while min_time+1 != max_time:
    # max_time+1は max_time=0まで求めるため
    middle_time = (min_time + max_time+1)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    new_list = [0]*N
    for i in range(N):
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            new_list[i] = ax
        else:
            new_list[i] = An[i]
    sum_candidate = sum(new_list)
    if An_s - sum_candidate == K or sum_candidate <=0 :
        break
    elif An_s - sum_candidate < K:
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい
print(middle_time)

Submission status: Wrong Answer

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 = 100 #10**6 * 10**6 #最大でかかる時間
middle_time = -1
while min_time+1 != max_time:
    # max_time+1は max_time=0まで求めるため
    middle_time = (min_time + max_time+1)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    new_list = [0]*N
    for i in range(N):
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            new_list[i] = ax
        else:
            new_list[i] = An[i]
    sum_candidate = sum(new_list)
    if An_s - sum_candidate == K or sum_candidate <=0 :
        break
    elif An_s - sum_candidate < K:
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい
print(middle_time)

Submission status: Wrong Answer

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 = 100 #10**6 * 10**6 #最大でかかる時間
middle_time = -1
while min_time+1 != max_time:
    # max_time+1は max_time=0まで求めるため
    middle_time = (min_time + max_time+1)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    new_list = [0]*N
    for i in range(N):
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            new_list[i] = ax
        else:
            new_list[i] = An[i]
    sum_candidate = sum(new_list)
    if An_s - sum_candidate == K or sum_candidate <=0 :
        break
    elif An_s - sum_candidate < K:
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい
print(middle_time)

Submission status: Wrong Answer

Solution code:
import heapq
N,K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
cost = max(sum(A)-K,0)
temp =F[:]
heapq.heapify(temp) 
for i in range(cost):
  temp_min = heapq.heappop(temp)	
  heapq.heappush(temp,temp_min)

 
print(max([temp[i] - F[i] for i in range(N)]))

Submission status: Wrong Answer

Solution code:

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
f = map(int, raw_input().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: Wrong Answer

Solution code:


n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
f = map(int, raw_input().split())
a.sort()
f.sort(reverse=True)

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

Submission status: Wrong Answer

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()
 
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)
    
    j = 0
    
    while right - left > 1 and j < 40: 
        
        j += 1
        
        if bm > k: left = middle
        elif bm == k:
            left = middle
            right = middle
        else: right = middle
            
        middle = int((left + right) / 2)
        bm = b(middle)
 
    if b(left) <= k: print(left)
    else: print(right)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
n, k = map(int, input().rstrip().split())
A = [int(i) for i in input().rstrip().split()]
A.sort(reverse = True)
F = [int(i) for i in input().rstrip().split()]
F.sort()
 
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 r % 1 == 0: result += int(r)
            else: result += int(r) + 1
    return result
 
if sum_A <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = int((left + right) / 2)
    bm = b(middle)
    
    j = 0
    
    while right - left > 1 and j < 100: 
        
        j += 1
        
        if bm > k: left = middle
        elif bm == k:
            left = middle
            right = middle
        else: right = middle
            
        middle = int((left + right) / 2)
        bm = b(middle)
 
    if b(left) <= k: print(left)
    else: print(right)

Submission status: Wrong Answer

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()
 
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 r % 1 == 0: result += int(r)
            else: result += int(r) + 1
    return result
 
if sum_A <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = int((left + right) / 2)
    bm = b(middle)
    
    j = 0
    
    while right - left > 1 and j < 10: 
        
        j += 1
        
        if bm > k: left = middle
        elif bm == k:
            left = middle
            right = middle
        else: right = middle
            
        middle = int((left + right) / 2)
        bm = b(middle)
 
    if b(left) <= k: print(left)
    else: print(right)

Submission status: Wrong Answer

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()
 
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 r % 1 == 0: result += int(r)
            else: result += int(r) + 1
    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
        elif bm == k:
            left = middle
            right = middle
        else: right = middle
            
        middle = int((left + right) / 2)
        bm = b(middle)
 
    if b(left) <= k: print(left)
    else: print(right)

Submission status: Wrong Answer

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

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 r % 1 == 0: result += int(r)
            else: result += int(r) + 1
    return result

if sum_A <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) // 2
    bm = b(middle)
    
    while right - left > 1:      
        
        if bm > k: left = middle
        elif bm == k:
            left = middle
            right = middle
        else: right = middle
            
        middle = (left + right) // 2
        bm = b(middle)

    if b(left) <= k: print(left)
    else: print(right)

Submission status: Wrong Answer

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

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

def b(p):
    result = sum_A
    i = 0
    while i < n and p >= F[i]:
        result -= p // F[i]
        i += 1
    return result

if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) // 2
    bm = b(middle)
    
    while right - left > 1:      
        
        if bm > k: left = middle
        elif bm == k: left = right = middle
        else: right = middle
          
        middle = (left + right) // 2
        bm = b(middle)
    if b(left) <= k: print(left)
    else: print(right)

Submission status: Wrong Answer

Solution code:
import sys
import math

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)

l,r = -1,10**12
while l+1 < r:
  mid = (l+r) / 2
  s = 0
  for i,j in zip(A,F):
    s += max(0, i - (mid / j))
  if s <= K:
    r = mid
  else:
    l = mid

print(math.ceil(r))

Submission status: Wrong Answer

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)

l,r = -1,10**12
while l+1 < r:
  mid = int((l+r) / 2)
  s = 0
  for i,j in zip(A,F):
    s += max(0, i - (mid / j))
  if s <= K:
    r = mid
  else:
    l = mid

print(r)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse = True)

"""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)]
 
def b(p):
    result = 0
    for i in range(n):
        x = A[i] - p / F[i]
        if x > 0: result += x
    return result

def b_int(p):
    result = 0
    for i in range(n):
        x = A[i] - p // F[i]
        if x > 0: result += x
    return result
 
if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) / 2
    bm = b(middle)
    
    #print(left, middle, right)
    #print(b(left), b(middle), b(right))
    #print(k, '\n')
    
    while right - left > 1:      
        
        if bm > k: left = middle
        elif bm == k: left = right = middle
        else: right = middle
        
        """if abs(bm - k) < 1:
            k -= 1"""
            
        middle = (left + right) / 2
        bm = b(middle)
        
        #print(left, middle, right)
        #print(b(left), b(middle), b(right))
        #print(k, '\n')
        
    
    if b_int(int(left)) == k: print(int(left))
    else:
        if b_int(int(left) + 1) <= k: print(int(left) + 1)
        else: print(int(left) + 2)

Submission status: Wrong Answer

Solution code:
import math

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
answer = 0

while l+1 < r:
  c = (l+r) / 2
  s = 0
  for i in range(N):
  	s += max(0, A[i] - (c / F[i]) )
  answer = math.ceil(s)
  if answer <= K:
    r = c
  else:
    l = c

print(answer)

Submission status: Wrong Answer

Solution code:
import math

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

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

print(math.ceil(r))

Submission status: Wrong Answer

Solution code:
import math

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,2*(10**5)+1

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

print(math.ceil(r))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse = True)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse = True)
 
P = [A[i]*F[i] for i in range(n)]
 
def b(p):
    result = 0
    for i in range(n):
        x = A[i] - p / F[i]
        if x > 0: result += x
    return result
 
if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) / 2
    bm = b(middle)
    
    while right - left > 2:      
        
        if bm > k: left = middle
        elif bm == k: left = right = middle
        else: right = middle
            
        middle = (left + right) / 2
        bm = b(middle)
        
    if bm == k: print(int(middle))
    elif bm < k:
        if b(int(middle)) < k: print(int(middle))
        else: print(int(middle) + 1)
    else:
        print(int(middle) + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse = True)
 
P = [A[i]*F[i] for i in range(n)]
 
def b(p):
    result = 0
    for i in range(n):
        x = A[i] - p / F[i]
        if x > 0: result += x
    return result
 
if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) / 2
    bm = b(middle)
    
    while right - left > 1:      
        
        if bm > k: left = middle
        else:
          old_right = right
          right = middle
        
        if abs(bm - k) < 1:
            k -= 1
            if b(right) > k: right = old_right
            
        middle = (left + right) / 2
        bm = b(middle)
        
    if b(int(left)) == k: print(int(left))
    elif b(int(right)) <= k: print(int(right))
    else: print(int(right) + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse = True)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse = True)
 
P = [A[i]*F[i] for i in range(n)]
 
def b(p):
    result = 0
    for i in range(n):
        result += A[i] - p / F[i]
    return result

if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) / 2
    bm = b(middle)
    while right - left > 1:
        
        if bm > k: left = middle
        else: right = middle
        
        if abs(bm - k) < 1: k -= 1
        
        middle = (left + right) / 2
        bm = b(middle)
        
    if b(int(left)) == k: print(int(left))
    elif b(int(right)) <= k: print(int(right))
    else: print(int(right) + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse = True)
 
P = [A[i]*F[i] for i in range(n)]
 
def b(p):
    result = 0
    for i in range(n):
        result += A[i] - p / F[i]
    return result
 
if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) / 2
    bm = b(middle)
    while right - left > 1 and abs(bm - k) >= 1:
        
        if bm > k: left = middle
        else: right = middle
        
        middle = (left + right) / 2
        bm = b(middle)
    
    if b(int(left)) == k: print(int(left))
    elif b(int(right)) <= k: print(int(right))
    else: print(int(right) + 1)

Submission status: Wrong Answer

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)

import math


def isValid(x):
  k_remain=k
  for i in range(n):
    si = math.ceil(a[i] - x / f[i])
    k_remain -= si
    if k_remain < 0:
      return False
  return True


left = 0
right = 10 ** 12

while left < right:
  mid = (left + right) // 2
  if isValid(mid):
    right = mid 
  else:
    left = mid+1
    
print(mid)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse = True)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse = True)
 
P = [A[i]*F[i] for i in range(n)]
 
def b(p):
    result = 0
    for i in range(n):
        result += A[i] - p / F[i]
    return result
 
if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) / 2
    bm = b(middle)
    while right - left > 1:
        
        if bm > k: left = middle
        else: right = middle
        
        middle = (left + right) / 2
        bm = b(middle)
    
    if b(int(left)) == k: print(int(left))
    elif b(int(right)) <= k: print(int(right))
    else: print(int(right) + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse = True)
 
P = [A[i]*F[i] for i in range(n)]
 
def b(p):
    result = 0
    for i in range(n):
        result += A[i] - p / F[i]
    return result
 
if sum(A) <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = (left + right) / 2
    bm = b(middle)
    while right - left > 1:
        
        if bm > k: left = middle
        else: right = middle
        
        middle = (left + right) / 2
        bm = b(middle)
    
    if b(int(right)) <= k: print(int(right))
    else: print(int(right) + 1)

Submission status: Wrong Answer

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)

import math

def isValid(x):
  s = []
  for i in range(n):
    si = math.ceil(a[i] - x / f[i])
    if si > a[i]:
      return False
    s.append(si)
  return sum(s) <= k


left = -1
right = 10 ** 12

while True:
  mid = (left + right) // 2
  if isValid(mid):
    right = mid
  else:
    left = mid
  if right <= left + 1:
    print(right)
    exit(0)

Submission status: Wrong Answer

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()
f.reverse()


import math


def isValid(x):
  s = []
  for i in range(n):
    s.append(max(math.ceil(a[i] - x / f[i]), 0))
  return sum(s) <= k


left = 0
right = 10 ** 12

while left + 1 < right:
  mid = (left + right) // 2
  if isValid(mid):
    right = mid
  else:
    left = mid + 1

print(left)