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:
n, k = map(int, input().split())
list_cost =list(map(int, input().split()))
list_difficulty =list(map(int, input().split()))

workout = 0
while True:
    max_point = 0
    min_point = 0
    max_index = 0
    list_cost.sort()
    list_difficulty.sort()
    list_difficulty.reverse()
    for index, cost in enumerate(list_cost):
        point = cost * list_difficulty[index]
        if point > max_point:
            max_point = point
            max_index = index
            
    if workout <= k and max_point > 0:
        list_cost[max_index] -= 1
        workout += 1
        continue
    else:
        print(max_point)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
list_cost =list(map(int, input().split()))
list_difficulty =list(map(int, input().split()))

workout = 0
while True:
    max_point = 0
    min_point = 0
    max_index = 0
    list_cost.sort()
    list_difficulty.sort()
    list_difficulty.reverse()
    for index, cost in enumerate(list_cost):
        point = cost * list_difficulty[index]
        if point > max_point:
            max_point = point
            max_index = index
            
    if workout <= k:
        list_cost[max_index] -= 1
        workout += 1
        continue
    else:
        print(max_point)
        break

Submission status: Wrong Answer

Solution code:
import math 

def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right

def costsum(x,y):
    siguma =0
    Asort = quick_sort(x)
    Fsort = quick_sort(y)
    for i in range(N):
        siguma = siguma + Asort[i]*Fsort[N-i-1]
    return siguma
def maxseki(x,y):
    seki = 0
    count = 0
    Asort = quick_sort(x)
    Fsort = quick_sort(y)
    for i in range(N):
        if seki < Asort[i]*Fsort[N-i-1]:
            seki = Asort[i]*Fsort[N-i-1]
            count = i
    return count

#input1 = input()
#input2 = input()
#input3 = input()
input1 ="11 14"
input2 ="3 1 4 1 5 9 2 6 5 3 5"
input3 ="8 9 7 9 3 2 3 8 4 6 2"
hairetu1 = input1.split()
hairetu2 = input2.split()
hairetu3 = input3.split()
N = int(hairetu1[0])
K = int(hairetu1[1])
A = [int(s) for s in hairetu2] 
F = [int(t) for t in hairetu3]

Asort = quick_sort(A)
Fsort = quick_sort(F)

for i in range(K):
    s=maxseki(Asort,Fsort)
    Asort[s]=Asort[s]-1


P = maxseki(Asort,Fsort)
maxcost = Asort[P]*Fsort[N-P-1]
print (maxcost)

Submission status: Wrong Answer

Solution code:
import math 

def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right


#input1 = input()
#input2 = input()
#input3 = input()
input1 ="11 14"
input2 ="3 1 4 1 5 9 2 6 5 3 5"
input3 ="8 9 7 9 3 2 3 8 4 6 2"
hairetu1 = input1.split()
hairetu2 = input2.split()
hairetu3 = input3.split()
N = int(hairetu1[0])
K = int(hairetu1[1])
A = [int(s) for s in hairetu2] 
F = [int(t) for t in hairetu3]

Asort = quick_sort(A)
Fsort = quick_sort(F)

for i in range(N):

    if Asort[i] != 0 and K != 0:
        if Asort[i] <= K:
            K = K - Asort[i]
            Asort[i] = 0
        else:
            Asort[i] = Asort[i] - K
            K = 0
Asort = quick_sort(Asort)

siguma =0

for i in range(N):
    siguma = siguma + Asort[i]*Fsort[N-i-1]

print (siguma)

Submission status: Wrong Answer

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

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

goal_max=max(time)
goal_min=0
goal=int((goal_max+goal_min)/2)

col={"-1":"NG"}
for i in range(goal_max+1):
   col[str(i)]=None

flag=True

while(flag):
   counter=0
   print(goal)
   for i in range(N):
      counter+=(A[i]-int(goal/F[i]))

   if(counter<=K):
      if col[str(goal-1)]=="NG":
         print(goal)
         flag=False
      else:
         col[str(goal)]="OK"
         goal_max=goal
         goal=int((goal_max+goal_min)/2)

   elif(counter>K):
      if col[str(goal+1)]=="OK":
         print(goal+1)
         flag=False
      else:
         col[str(goal)]="NG"
         goal_min=goal
         goal=int((goal_max+goal_min)/2)

Submission status: Wrong Answer

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

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

goal_max=max(time)
goal_min=0
goal_ave=int((goal_max+goal_min)/2)
goal=int((goal_max+goal_min)/2)

col={"-1":"NG"}
for i in range(goal_max+1):
   col[str(i)]=None

flag=True

while(flag):
   counter=0
   print(goal)
   for i in range(N):
      counter+=(A[i]-int(goal/F[i]))

   if(counter<=K):
      if col[str(goal-1)]=="NG":
         print(goal)
         flag=False
      else:
         col[str(goal)]="OK"
         if goal==int((goal+goal_ave)/2):
            goal=int((goal+goal_ave)/2)-1
            print("b")         
         #elif goal!=goal_ave:
         #   goal=int((goal+goal_ave)/2)
         #   print("a")
         else:
            goal=int((goal+goal_min)/2)
            print("c")

   elif(counter>K):
      if col[str(goal+1)]=="OK":
         print(goal+1)
         flag=False
      else:
         col[str(goal)]="NG"
         if goal==int((goal+goal_ave)/2):
            goal=int((goal+goal_ave)/2)+2
         #elif goal!=goal_ave:
         #   goal=int((goal+goal_ave)/2)    
         else:
            goal=int((goal+goal_max)/2)

Submission status: Wrong Answer

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

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

goal_max=max(time)
goal_min=0
goal_ave=int((goal_max+goal_min)/2)
goal=int((goal_max+goal_min)/2)

col={"-1":"NG"}
for i in range(goal_max+1):
   col[str(i)]=None

flag=True

while(flag):
   counter=0
   print(goal)
   for i in range(N):
      counter+=(A[i]-int(goal/F[i]))

   if(counter<=K):
      if col[str(goal-1)]=="NG":
         print(goal)
         flag=False
      else:
         col[str(goal)]="OK"
         if goal==int((goal+goal_ave)/2):
            goal=int((goal+goal_ave)/2)-1
            print("b")         
         #elif goal!=goal_ave:
         #   goal=int((goal+goal_ave)/2)
         #   print("a")
         else:
            goal=int((goal+goal_min)/2)
            print("c")

   elif(counter>K):
      if col[str(goal+1)]=="OK":
         print(goal+1)
         flag=False
      else:
         col[str(goal)]="NG"
         if goal==int((goal+goal_ave)/2):
            goal=int((goal+goal_ave)/2)+1  
         #elif goal!=goal_ave:
         #   goal=int((goal+goal_ave)/2)    
         else:
            goal=int((goal+goal_max)/2)

Submission status: Wrong Answer

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

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

goal_max=max(time)
goal_min=0
goal_ave=int((goal_max+goal_min)/2)
goal=int((goal_max+goal_min)/2)

col={"-1":"NG"}
for i in range(goal_max+1):
   col[str(i)]=None

flag=True

while(flag):
   counter=0
   print(goal)
   for i in range(N):
      counter+=(A[i]-int(goal/F[i]))

   if(counter<=K):
      if col[str(goal-1)]=="NG":
         print(goal)
         flag=False
      else:
         col[str(goal)]="OK"
         if goal==int((goal+goal_ave)/2):
            goal=int((goal+goal_ave)/2)-1
            print("b")         
         #elif goal!=goal_ave:
         #   goal=int((goal+goal_ave)/2)
         #   print("a")
         else:
            goal=int((goal+goal_min)/2)
            print("c")

   elif(counter>K):
      if col[str(goal+1)]=="OK":
         print(goal+1)
         flag=False
      else:
         col[str(goal)]="NG"
         if goal==int((goal+goal_ave)/2):
            goal=int((goal+goal_ave)/2)-1  
         #elif goal!=goal_ave:
         #   goal=int((goal+goal_ave)/2)    
         else:
            goal=int((goal+goal_max)/2)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
As = np.sort(list(map(int, input().split())))
Fs = np.sort(list(map(int, input().split())))[::-1]
l  = As*Fs
left = 0
right = max(l)
while right-left>1:
    mid = left + (right - left)/2
    if np.maximum(As-mid//Fs , 0).sum()<=K:
        right = mid
    else:
        left = mid
print(int(right))

Submission status: Wrong Answer

Solution code:
N,K = (int(num) for num in input().split())
Araw= list(int(num1) for num1 in input().split())
Fraw= list(int(num2) for num2 in input().split())

if sum(Araw)<=K:
    print(0)
else:
    A = sorted(Araw)
    F = sorted(Fraw)
    S = [0] * N

    for i in range(0,N,1):
        S[i] = A[i] * F[N-1-i]

    S, A = (list(x) for x in zip(*sorted(zip(S, A))))

    for i in range(K):
        S[N-1] = S[N-1] - (S[N-1] / A[N-1])
        A[N-1] = A[N-1] - 1
        S, A = (list(x) for x in zip(*sorted(zip(S, A))))
    
    print(S[N-1])

Submission status: Wrong Answer

Solution code:
N,K = (int(num) for num in input().split())
Araw= list(int(num1) for num1 in input().split())
Fraw= list(int(num2) for num2 in input().split())

if sum(Araw)<=K:
    print(0)
else:
    A = sorted(Araw)
    F = sorted(Fraw)
    S = [0] * N

    for i in range(0,N,1):
        S[i] = A[i] * F[N-1-i]

    S, A = (list(x) for x in zip(*sorted(zip(S, A))))

    for i in range(K):
        S[N-1] = S[N-1] - (S[N-1] / A[N-1])
        A[N-1] = A[N-1] - 1
        S, A = (list(x) for x in zip(*sorted(zip(S, A))))
    
    print(S[N-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()

import numpy as np

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

left = 0
right = np.max(a*f_)

while left + 1 < right:
    mid = (left + right)//2
    x = np.maximum(0, a - (mid//f_) ).sum() <= k
    if x:
        right = mid
    else:
        left = mid

print(right)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
AS = list(map(int, input().split()))
FS = list(map(int, input().split()))
AS.sort(); FS.sort(reverse=True)

def isValid(x):
    import math
    trains = 0
    for i in range(N):
        num = AS[i] * FS[i]
        if num <= K: continue
        trains += math.ceil((num - x) / FS[i])
    return trains <= K

def binarySearch(lo, hi):
    if lo >= hi:
        return lo
    mid = lo + (hi - lo) // 2
    if isValid(mid):
        return binarySearch(lo, mid)
    else:
        return binarySearch(mid + 1, hi)
            
print(binarySearch(0, max(AS[i] * FS[i] for i in range(N))))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
AS = list(map(int, input().split()))
FS = list(map(int, input().split()))
AS.sort(); FS.sort(reverse=True)

def isValid(x):
    import math
    trains = 0
    for i in range(N):
        num = AS[i] * FS[i]
        if num <= K: continue
        trains += math.ceil((num - K) / FS[i])
    return trains <= K

def binarySearch(lo, hi):
    if lo >= hi:
        return lo
    mid = lo + (hi - lo) // 2
    if isValid(mid):
        return binarySearch(lo, mid)
    else:
        return binarySearch(mid + 1, hi)
            
print(binarySearch(0, max(AS[i] * FS[i] for i in range(N))))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
F = [int(x) for x in input().split()]
# N, K = [3, 5]
# A = [4, 2, 1]
# F = [2, 3, 1]

A = sorted(A)
F = list(reversed(sorted(F)))

# 最大値を最小化する二分探索
l = -1
r = int(10e12)
while (l + 1 < r):
    c = (l + r) // 2
    max_sum = 0
    for i in range(N):
        max_sum += max(A[i] - c / F[i], 0)

    if max_sum <= K:
        r = c
    else:
        l = c

print(r)

Submission status: Wrong Answer

Solution code:
#E
N,K = map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse = True)
T = [A[i]*F[i] for i in range(0,N)]
# 二分法
ma = max(A)*max(F)
mi = 0
line = 0


while ma-mi > 0.9:
    count = 0
    line = (ma+mi)/2
    
    
    for i in range(0,N):
        if T[i] > line:
            count += A[i]-line//F[i]
    else:
        if count > K:
            mi = line
        else:
            ma = line
    

print(int(line))

Submission status: Wrong Answer

Solution code:
#E
N,K = map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse = True)
T = [A[i]*F[i] for i in range(0,N)]
# 二分法
ma = max(A)*max(F)
mi = 0
line = 0


while ma-mi > 0.5:
    count = 0
    line = (ma+mi)/2
    
    
    for i in range(0,N):
        if T[i] > line:
            count += A[i]-line//F[i]
    else:
        if count > K:
            mi = line
        else:
            ma = line
    

print(int(line))

Submission status: Wrong Answer

Solution code:
#E
N,K = map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse = True)
T = [A[i]*F[i] for i in range(0,N)]
# 二分法
ma = max(A)*max(F)
mi = 0
line = 0


while ma-mi > 1:
    count = 0
    line = (ma+mi)/2
    
    
    for i in range(0,N):
        if T[i] > line:
            count += A[i]-line//F[i]
    else:
        if count > K:
            mi = line
        else:
            ma = line
    

print(int(line))

Submission status: Wrong Answer

Solution code:
#E
N,K = map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse = True)
T = [A[i]*F[i] for i in range(0,N)]
# 二分法
ma = max(A)*min(F)
mi = 0
line = 0


while ma-mi > 1:
    count = 0
    for i in range(0,N):
        if T[i] > line:
            count += A[i]-line//F[i]
    else:
        if count > K:
            mi = line
        else:
            ma = line
    line = (ma+mi)/2

print(int(line))

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
A_n = list(map(int,input().split()))
F_n = list(map(int,input().split()))

A_n.sort()
F_n.sort(reverse=True)

i =0
while K>0:
    if A_n[i]-K>0:
            A_n[i] -= K
            K = 0
    else:
        K -=A_n[i]
        A_n[i]=0
        i +=1
    if i ==N: K=0

ans =0
for i in range(N):
    ans +=A_n[i]*F_n[i]
    
print(ans)

Submission status: Wrong Answer

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

a[int(a.index(max(a)))] -= 1
ans = []
for x, y in zip(a, f):
    ans.append(x * y)
for z in range(k):
    ans[int(ans.index(max(ans)))] -= f[int(ans.index(max(ans)))]
if (max(ans) < 0):
    print(0)
    exit()
print(max(ans))

Submission status: Wrong Answer

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

## 修行前の最短: M
M = max([a*f for a, f in zip(A, F)])

## 積の最小をxにできるか。
## x//f以下である必要がある。
def is_possible(x):
    return sum([a-x//f for a, f in zip(A, F)]) <= K

## 2分探索
left = -1
right = M
while left + 1 < right:
    mid = (left + right)//2
    if is_possible(mid):
        right = mid
    else:
        left = mid

print(right)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

#output
import numpy as np
A = np.array(A)
F = np.array(F)

A = np.sort(A)[::-1]
F = np.sort(F)
l = A*F
M = max(l)

for i in range(M):
    x = np.sum(A-i/F)
    if x <= K:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

#output
import numpy as np
A = np.array(A)
F = np.array(F)

A = np.sort(A)[::-1]
F = np.sort(F)
l = A*F
M = max(l)

for i in range(M):
    x = A-i/F
    y = np.sum(x[x>0])
    if y <= K:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse = True)
left = 0
right = 10 ** 12
while left < right:
    mid = (left + right) // 2
    #print(left, mid, right)
    sum = 0
    for i in range(len(a)):
        cost = max(a[i]-mid/f[i], 0)
        sum += cost
    if sum <= k:
        right = mid
    elif mid == left:
        #print(mid)
        mid += 1
        break
    else:
        left = mid
print(mid)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    return


# B
def B():
    return


# C
def C():
    n = I()
    for i in range(int(n ** 0.5), 0, -1):
        if n % i == 0:
            print(i + n // i - 2)
            return
    return


# D
def D():
    a, b, x = LI()
    if (x <= a * a * b / 2):
        print(math.degrees(math.atan(a * b * b / x / 2)))
    else:
        print(math.degrees(math.atan(2 * (a * a * b - x) / a ** 3)))
    return


# E
def E():
    n, k = LI()
    a = LI()
    f = LI()
    a.sort()
    f.sort(reverse=True)
    left = 0
    right = 0
    for a_i, f_i in zip(a, f):
        right = max(a_i * f_i, right)
    while(left!=right):
        mid = (left+right)>>1
        score = 0
        for i in range(n):
            if a[i]*f[i]>mid:
                score+=a[i]-mid//f[i]
        if score<=k:
            right=mid
        else:
            left=mid+1
    print(left)
    return


# F
def F():
    return


# Unittest
def resolve():
    E()
    return

Submission status: Wrong Answer

Solution code:
import math

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

A.sort(reverse=True)
F.sort()
max_af = 0
for ind,a in enumerate(A):
    max_af = max(a*F[ind], max_af)

if(sum(A)<=K):
    print(0)
else:
    lower = -1
    higher = 10**12+1

    while(higher-lower>1):
        k = K
        x = lower + (higher - lower)//2
        for ind,a in enumerate(A):
            mu = a*F[ind]
            if(mu<=x):
                continue
            else:
                k -= math.ceil((mu-x)/F[ind])
        if(k>=0):
            higher = x
        else:
            lower = x

    print(x)

Submission status: Wrong Answer

Solution code:
import math

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

A.sort(reverse=True)
F.sort()
max_af = 0
for ind,a in enumerate(A):
    max_af = max(a*F[ind], max_af)

if(sum(A)<=K):
    print(0)
else:
    lower = -1
    higher = max_af

    while(higher-lower>1):
        k = K
        x = lower + (higher - lower)//2
        for ind,a in enumerate(A):
            mu = a*F[ind]
            if(mu<=x):
                continue
            else:
                k -= math.ceil((mu-x)/F[ind])
        if(k>=0):
            higher = x
        else:
            lower = x

    print(x)

Submission status: Wrong Answer

Solution code:
import math

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

A.sort(reverse=True)
F.sort()
max_af = 0
for ind,a in enumerate(A):
    max_af = max(a*F[ind], max_af)

if(sum(A)<=K):
    print(0)
else:
    lower = -1
    higher = max_af

    while(higher-lower>1):
        k = K
        x = (lower+higher)//2
        for ind,a in enumerate(A):
            mu = a*F[ind]
            if(mu<=x):
                continue
            else:
                k -= math.ceil((mu-x)/F[ind])
        if(k>=0):
            higher = x
        else:
            lower = x

    print(x)

Submission status: Wrong Answer

Solution code:
import math

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

A.sort(reverse=True)
F.sort()
max_af = 0
for ind,a in enumerate(A):
    max_af = max(a*F[ind], max_af)

if(sum(A)<=K):
    print(0)
else:
    lower = 1
    higher = max_af

    while(higher-lower>1):
        k = K
        x = (lower+higher)//2
        for ind,a in enumerate(A):
            mu = a*F[ind]
            if(mu<=x):
                continue
            else:
                k -= math.ceil((mu-x)/F[ind])
        if(k>=0):
            higher = x
        else:
            lower = x

    print(x)

Submission status: Wrong Answer

Solution code:
import math

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

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

if(sum(A)<=K):
    print(0)
else:
    lower = 1
    higher = A[0]*F[-1]
    while(lower<higher-1):
        k = K
        x = (lower+higher)//2
        for ind,a in enumerate(A):
            mu = a*F[ind]
            if(mu<=x):
                continue
            else:
                k -= math.ceil((mu-x)/F[ind])
        if(k>=0):
            higher = x
        else:
            lower = x
    print(x)

Submission status: Wrong Answer

Solution code:
import time
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = sorted(list(map(int, input().split())))

ans = 100000000000
count = 0

for j in range(K+1):

    A.sort(reverse=True)

    muls = [x * y for(x,y) in zip(A, F)]
    # print(muls)

    tmp = max(muls)
    if(ans > tmp):
        ans = tmp

    idxs = [i for i, val in enumerate(muls) if(val == tmp)]

    if(len(idxs) >= (K+1-count) or ans == 0 or count >= K):
        break 

    for idx in idxs:
        A[idx] -= 1
        count += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import time
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = sorted(list(map(int, input().split())))

ans = 100000000000
count = 0

for j in range(K+1):

    A.sort(reverse=True)

    muls = [x * y for(x,y) in zip(A, F)]
    # print(muls)

    tmp = max(muls)
    if(ans > tmp):
        ans = tmp

    idxs = [i for i, val in enumerate(muls) if(val == tmp)]

    if(len(idxs) >= (K+1-count) or ans == 0 or count > K):
        break 

    for idx in idxs:
        A[idx] -= 1
        count += 1
    
print(ans)

Submission status: Wrong Answer

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

a.sort()
f.sort()
tmp_idx = 0
for i in range(n):
  if a[i] >= k:
    a[i] -= k
    break
  else:
    k -= a[i]
    a[i] = 0
a.sort(reverse=True)
ans = 0
for aa,ff in zip(a,f):
  ans += aa*ff
print(ans)

Submission status: Wrong Answer

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

ans = 10 ** 12
count = 0
for j in range(K+1):

    A.sort(reverse=True)
    muls = [x * y for(x,y) in zip(A, F)]

    tmp = max(muls)

    if(ans == tmp):
        count += 1

    ans = tmp

    if(ans == 0 or j == K or count == N):
        break

    idx = muls.index(tmp)
    A[idx] -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, k = map(int, input().split())
arrayA = list(map(int, input().split()))
arrayF = list(map(int, input().split()))

arrayA.sort()
arrayF.sort(reverse = True)

i = 0
while i < n and k > arrayA[i] :
    k -= arrayA[i]
    i += 1
if i < n: arrayA[i] = arrayA[i]-k

arrayA = np.array(sorted(arrayA[i:]))
arrayF = np.array(arrayF[i:])

ans = int(np.sum(arrayA*arrayF) )
print(ans)

Submission status: Wrong Answer

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

Asum=sum(A)-K

left=-1
right=2*10**17

while left+1<right:
  mid=(left+right)//2
  tmp=0
  for i in range(N):
    tmp+=mid//F[i]
  if tmp>=Asum:
    right=mid
  else:
    left=mid
print(right)

Submission status: Wrong Answer

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

Asum=sum(A)-K

left=-1
right=10**12

while left+1<right:
  mid=(left+right)//2
  tmp=0
  for i in range(N):
    tmp+=mid//F[i]
  if tmp>=Asum:
    right=mid
  else:
    left=mid
print(right)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
#二分探索をつくる
L = -1
R = 10**6 +1 
while R-L>1:
    Mid = (L+R)//2
    tmp = 0
    for a,f in zip(A,F):
        tmp += max(0, a-Mid//f)
    if tmp<=K:
        R = Mid
    else:
        L = Mid
print(R)

Submission status: Wrong Answer

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()
#修行
for i in range(k):
    a[0] -= 1
    a.sort(reverse=True)
ans = 0
#本番
for i,j in zip(a,f):
    ans=max(ans,i*j)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        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 in range(N):
                s += max(0, A[i] - mid / F[i])
            if s <= K:
                r = mid
            else:
                l = mid
        print(r)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Wrong Answer

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

l = 0
r = 10**12 + 1

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

print(r)

Submission status: Wrong Answer

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

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

print(x_cadidate)

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int, input().split())
alst = list(map(int, input().split()))
flst = list(map(int, input().split()))

sorted_flst = sorted(flst, key = lambda x: -x)
sorted_alst = sorted(alst)

pair_lst = []
for a, b in zip(sorted_flst, sorted_alst):
    pair_lst.append((a*b, a))
sorted_pair_lst = sorted(pair_lst, key = lambda x:-x[0])

def judge(sorted_pair_lst, x):
    cnt = 0
    for pair in sorted_pair_lst:
        if pair[0] <= x:
            return True
        else:
            cnt += math.ceil((pair[0] - x) / pair[1])
            if cnt > k:
                return False
    return True

low = 0
high = 10**15
while high - low > 1:
    middle = (low+high) // 2
    if judge(sorted_pair_lst, middle):
        high = middle
    else:
        low = middle
print(high) if judge(sorted_pair_lst, high) else print(low)