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 sys
import math
import bisect
 
 
sys.setrecursionlimit(1000000000)
def input():
    return sys.stdin.readline().strip()
 
def iinput():
    return int(input())
 
def finput():
    return float(input())
 
def tinput():
    return input().split()
 
def rinput():
    return map(int, tinput())
 
def rlinput():
    return list(rinput())
 
def modst(a, s):
    res = 1
    while s:
        if s % 2:
            res *= a
        a *= a
        s //= 2
    return res

 
def main():
    n, k = rinput()
    a = sorted(rlinput())
    s = sorted(rlinput())
    l, res = -1, 10 ** 12
    while res - l > 1:
        m = (res + l) // 2
        q = k    
        for i in range(n):
            w = a[i] - (m // s[i])
            q -= max(0, w)
        if q < 0:
            l = m
        else:
            res = m
    print(res)        
main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
 
 
sys.setrecursionlimit(1000000000)
def input():
    return sys.stdin.readline().strip()
 
def iinput():
    return int(input())
 
def finput():
    return float(input())
 
def tinput():
    return input().split()
 
def rinput():
    return map(int, tinput())
 
def rlinput():
    return list(rinput())
 
def modst(a, s):
    res = 1
    while s:
        if s % 2:
            res *= a
        a *= a
        s //= 2
    return res

 
def main():
    n, k = rinput()
    a = sorted(rlinput())
    s = sorted(rlinput())
    l, res = -1, 10 ** 12
    while res - l > 1:
        m = (res + l) // 2
        q = k    
        for i in range(n):
            w = a[- i - 1] - (m // s[- i - 1])
            q -= max(0, w)
        if q < 0:
            l = m
        else:
            res = m
    print(res)        
main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
# from bisect import *
from collections import *
from heapq import *
# import itertools
import math
# INF = 10**9
# MOD = 10**9+7

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
F = [int(x) for x in input().split()]
F.sort(reverse = 1)
l, r = -1, 10**11
while l+1 < r:
    x = (l+r)//2
    c = 0
    for a, f in zip(A, F):
        if a*f > x:
            c += max(0,a-x//f)
    if c > K:
        l = x
    else:
        r = x
print(r)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
# from bisect import *
from collections import *
from heapq import *
# import itertools
import math
# INF = 10**9
# MOD = 10**9+7

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
F = [int(x) for x in input().split()]
F.sort(reverse = 1)
l, r = -1, 10**11
while l+1 < r:
    x = (l+r)//2
    c = 0
    for a, f in zip(A, F):
        if a*f > x:
            c += a-x//f
    if c > K:
        l = x
    else:
        r = x
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()
F.sort(reverse=True)
l, r = -1, 10 ** 12


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


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


print(r)

Submission status: Wrong Answer

Solution code:
import sys
import heapq


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

input = sys.stdin.readline

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

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

Submission status: Wrong Answer

Solution code:
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[:]
for i in range(cost):
  ind = 0

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

Submission status: Wrong Answer

Solution code:
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[:]
for i in range(cost):
  ind = temp.index(min(temp))

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

Submission status: Wrong Answer

Solution code:
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[:]
for i in range(cost):
  #ind = temp.index(min(temp))
  ind = 0
  temp[ind] += F[ind]
 
print(max([temp[i] - F[i] for i in range(N)]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

import math
import sys

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

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

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

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

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
N,K =map(int,input().split( ))
A=[int(i) for i in input().split( )]
F=[int(i) for i in input().split( )]
A=sorted(A)
F=sorted(F,reverse=True)
cost=[0]*N
shu=0
flag=0
if K<sum(A):
    for i in range(N):
        cost[i]=A[i]*F[i]
    cost_add=np.argsort(cost)
    start=0
    end=cost[cost_add[-1]]
    while True:
        mid = start+(end - start)//2
        for i in range(N-1,0,-1):
            if cost[cost_add[i]]>mid:
                k=math.ceil(cost[cost_add[i]]-mid)/F[cost_add[i]]
                shu+=k
                if shu > K:
                    start=mid+1
                    break
            else:
                if shu==K:
                    if cost[cost_add[i+1]]<=mid:
                        flag=1
                        print(cost[cost_add[i+1]])
                        break
                else:
                    end=mid
                    break
        if flag==1:
            break
        if end == start:
            print(start)
            break
else:
    print('0')

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
N,K =map(int,input().split( ))
A=[int(i) for i in input().split( )]
F=[int(i) for i in input().split( )]
A=sorted(A)
F=sorted(F,reverse=True)
cost=[0]*N
shu=0
flag=0
if K<sum(A):
    for i in range(N):
        cost[i]=A[i]*F[i]
    cost_add=np.argsort(cost)
    start=0
    end=cost[cost_add[-1]]
    while True:
        mid = start+(end - start)//2
        for i in range(N-1,0,-1):
            if cost[cost_add[i]]>mid:
                k=math.ceil(cost[cost_add[i]]-mid)/F[cost_add[i]]
                shu+=k
                if shu > K:
                    start=mid+1
                    break
            else:
                if shu==K:
                    if cost[cost_add[i+1]]<=mid:
                        flag=1
                        break
                else:
                    end=mid
                    break
        if flag==1:
            print(mid)
            break
        if end == start:
            print(start)
            break
else:
    print('0')

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

Submission status: Wrong Answer

Solution code:
import numpy as np
i8 = np.int64
i4 = np.int32
def solve(A,F,K):
  min_ = 0
  max_ = 10**12
  while min_ < max_:
    mid = (min_ + max_) // 2
    count = A - mid // F
    sum_ = count[count > 0].sum()
    if sum_ <= K:
      max_ = mid
    else:
      min_ = mid + 1
def main():
  stdin = open('/dev/stdin','rb')
  pin = np.fromstring(stdin.read(),i8,sep=' ')
  N, K = pin[:2]
  A = pin[2: N + 2]
  F = pin[N+2: 2*N+2]
  A = np.sort(A)[::-1]
  F.sort()
  res = solve(A,F,K)
  print(res)
if __name__ == '__main__':
  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=sorted(a)
f=sorted(f,reverse=True)

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

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

Submission status: Wrong Answer

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

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

l=-1
r=10^12

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

l=-1
r=10^12

def ok():
    s=0
    for i in range(n):
        s+=max(0,a[i]-c/f[i])
    return s<=k

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

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)

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

left = 0
right = 1e12
while left+1 < right:
    mid = int(left + (right-left)//2)
    if isOk(mid):
        right = mid
    else:
        left = mid
if sum(A) <= k:
    right = 0
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=sorted(a)
f=sorted(f,reverse=True)

l=-1
r=10^12

def ok():
    s=0
    for i in range(n):
        s+=max(0,a[i]-c/f[i])
    return s<=k

while(l+1<r):
    c=(l+r)//2
    
    if ok():
        r=c
    else:
        l=c
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()
F.sort(reverse=True)

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

left = 0
right = 1e12
while left+1 < right:
    mid = int(left + (right-left)//2)
    if isOk(mid):
        right = mid
    else:
        left = mid
if sum(A) <= k:
    right = 0
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)

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

left = 0
right = 1e12
while left+1 < right:
    mid = left + (right-left)//2
    if isOk(mid):
        right = mid
    else:
        left = mid
if sum(A) <= k:
    right = 0
print(right)

Submission status: Wrong Answer

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

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

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

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

print(nibutan())

Submission status: Wrong Answer

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

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

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

N,K = IL()
a = IL()
f = IL()
a.sort()
f.sort(reverse=True)

print(nibutan())

Submission status: Wrong Answer

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

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

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

N,K = IL()
a = IL()
f = IL()
a.sort()
f.sort(reverse=True)

print(nibutan())

Submission status: Wrong Answer

Solution code:

def check(res,a,f,k):
    for sa,sf in zip(a,f):
        if sa*sf <= res:
            continue
        k -= sa - (res // sf)
        if k < 0:
            return False
    return True


def nibun(l,r,a,f,k):
    if r == l:
        return l
    flag = (l+r)//2
    if check(flag,a,f,k):
        return nibun(l,flag,a,f,k)
    else:
        return nibun(flag+1,r,a,f,k)

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

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

    return nibun(0,10*13,a,f,k)


print(main())

Submission status: Wrong Answer

Solution code:

def check(res,a,f,k):
    for sa,sf in zip(a,f):
        if sa*sf <= res:
            continue
        k -= sa - (res // sf)
        if k < 0:
            return False
    return True


def nibun(l,r,a,f,k):
    if r == l:
        return l
    flag = (l+r)//2
    if check(flag,a,f,k):
        return nibun(l,flag,a,f,k)
    else:
        return nibun(flag+1,r,a,f,k)

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

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

    return nibun(0,10*12,a,f,k)


print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

n,k = map(int,input().split())

a = list(map(int,input().split()))
#na = np.array(
a.sort() #)

f = list(map(int,input().split()))
#nf = np.array(
f.sort(reverse = True) #)

"""
print(a)
print(f)
"""


ans = [i*j for i,j in zip(a,f)]

print(sum(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()))
B=sorted(A)
G=sorted(F)[::-1]

Allcost=0
for i in range(N):
  Allcost+=B[i]*G[i]
  
mcost=0

T=0
for i in range(N):
  T+=B[i]
  if T >= K:
    mcost+=(K-sum(B[0:i]))*(G[i])
    break
  else:
    mcost+=B[i]*G[i]
    
print(Allcost-mcost)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = np.array(a)
f = np.array(f)

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

#print(a)
#print(f)

m = sum(a)

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

a = []
f = []
n = 0

def rec(l, r, k):
    if l+1 < r:
        mid = (l + r) // 2
        s = 0
        for i in range(n):
            s += max(a[i] - mid / f[i], 0)
        if s <= k:
            return rec(l, mid, k)
        else:
            return rec(mid, r, k)
    else:
        return r

def main():
    global a, f, n
    n, k = map(int, input().strip().split())
    a = list(map(int, input().strip().split()))
    f = list(map(int, input().strip().split()))
    a = sorted(a)
    f = sorted(f, reverse=True)
    print(rec(-1, 10**12, k))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

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

    t = [(ae, fe) for ae, fe in zip(a, f)]

    def bs(l, m, r):
        if l + 1 >= r:
            return r
        cnt = 0
        for ae, fe in t:
            train = max(0, ceil((ae * fe - m) / fe))
            cnt += train

        if cnt <= k:
            l, m, r = l, (m - l) // 2 + l, m
            return bs(l, m, r)

        else:
            l, m, r = m + 1, (r - m - 1) // 2 + m + 1, r
            return bs(l, m, r)

    mx = max([ae * fe for ae, fe in t])
    ans = bs(0, mx // 2, mx)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


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

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

    t = [(ae, fe) for ae, fe in zip(a, f)]

    def bs(l, m, r):
        if l == m or m == r:
            return m
        cnt = 0
        for ae, fe in t:
            train = max(0, ceil((ae * fe - m) / fe))
            cnt += train

        if cnt <= k:
            l, m, r = l, (m - l) // 2 + l, m
            return bs(l, m, r)

        else:
            l, m, r = m + 1, (r - m - 1) // 2 + m + 1, r
            return bs(l, m, r)

    mx = max([ae * fe for ae, fe in t])
    ans = bs(0, mx // 2, mx)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


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

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

    t = [(ae, fe) for ae, fe in zip(a, f)]

    def bs(l, m, r):
        if l == m:
            return m
        cnt = 0
        for ae, fe in t:
            train = max(0, ceil((ae * fe - m) / fe))
            cnt += train

        if cnt <= k:
            l, m, r = l, (m - l) // 2 + l, m
            return bs(l, m, r)

        else:
            l, m, r = m + 1, (r - m - 1) // 2 + m + 1, r
            return bs(l, m, r)

    ans = bs(0, 10 ** 12 // 2, 10 ** 12)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    A.sort()
    F.sort(reverse=True)
    AF = zip(A, F)

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

        if cnt > K:
            return False
        else:
            return True

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

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

sol()

Submission status: Wrong Answer

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

minT, maxT = -1, max([A[i] * F[i] for i in range(N)])
while maxT - minT > 1:
    midT = minT + (maxT - minT) // 2
    if sum([A[i] - midT // F[i] for i in range(N)]) > K:
        minT = midT
    else:
        maxT = midT

print(maxT)

Submission status: Wrong Answer

Solution code:
import math

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

minT, maxT = -1, max([A[i] * F[i] for i in range(N)])
while True:
    if maxT - minT == 1:
        print(maxT)
        exit()
    midT = minT + (maxT - minT) // 2
    k = 0
    for i in range(N):
        k += A[i] - midT // F[i]
    if k > K:
        minT = midT
    else:
        maxT = midT

Submission status: Wrong Answer

Solution code:
from numpy import*
(_,k),*t=[int32(t.split())for t in open(0)]
A,F=map(sort,t)
s=sum(A)
l=-1
r=10**12
while r-l>1:
 m=l+r>>1
 if s-sum(minimum(A,m//F[::-1]))>k:l=m
 else:r=m
print(r)

Submission status: Wrong Answer

Solution code:
from numpy import*
(_,k),*t=[int32(t.split())for t in open(0)]
A,F=map(sort,t)
s=A.sum()
l=-1
r=10**12
while r-l>1:
 m=l+r>>1
 if s-sum(minimum(A,m//F[::-1]))>k:l=m
 else:r=m
print(r)

Submission status: Wrong Answer

Solution code:
i=lambda:sorted(map(int,input().split()))
n,k=i()
z=i(),i()[::-1]
o=10**12
g=-1
while o-g>1:
 m,l=o+g>>1,k
 for a,f in zip(*z):l-=max(0,a-m//f)
 if l<0:g=m
 else:o=m
print(o)

Submission status: Wrong Answer

Solution code:
def bisect_left(f, x, hi):
  lo = 0
  while lo < hi:
    mid = (hi + lo) // 2
    score = f * mid
    if x < score:
      hi = mid
    else:
      lo = mid + 1
  return lo
  
def main():
  n, k = map(int, input().split())
  a_list = list(map(int, input().split()))
  f_list = list(map(int, input().split()))

  a_list.sort()
  f_list.sort(reverse=True)

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

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import sys
import heapq


def main():
    n, k = [int(s) for s in sys.stdin.readline().strip().split()]
    a = [int(s) for s in sys.stdin.readline().strip().split()]
    f = [int(s) for s in sys.stdin.readline().strip().split()]
    # n, k = 3, 5
    # a = [4, 2,1]
    # f = [2, 3, 1]

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

    def possible(x1):
        improved = 0
        for i in range(n):
            before = a[i] * f[i]
            if before > x1:
                needed_to_be_reduced = before - x1
                if needed_to_be_reduced % f[i] == 0:
                    plus_one = 0
                else:
                    plus_one = 1
                improved += (needed_to_be_reduced // f[i]) + plus_one
                if improved > k:
                    return False
        return True

    def b_search():
        lo = -1
        hi = 10 ** 12
        # (lo, hi]
        # hi is always possible
        # lo might be possible

        while lo < hi:
            mid = (lo + hi) // 2
            if possible(mid):
                hi = mid
            else:
                lo = mid+1
        return hi

    ans = b_search()
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
from numpy import*
import sys
input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n,k=map(int,input().split())
    a=array(sorted(map(int,input().split())),dtype=int64)
    b=array(sorted(map(int,input().split())),dtype=int64)
    #print(a,b)
    ok=max(a)*max(b)
    ng=-1
    
    def check(a,b,mid,k):
        if sum(a-mid//b)<=k:
            return 1
        else:
            return 0
            
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if check(a,b,mid,k):
            ok=mid
        else:
            ng=mid
    print(ok)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from numpy import*
import sys
input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n,k=map(int,input().split())
    a=array(sorted(map(int,input().split())))
    b=array(sorted(map(int,input().split())))
    #print(a,b)
    ok=max(a)*max(b)
    ng=-1
    
    def check(a,b,mid,k):
        if sum(a-mid//b)<=k:
            return 1
        else:
            return 0
            
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if check(a,b,mid,k):
            ok=mid
        else:
            ng=mid
    print(ok)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():

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

    if K >= sum(A): return 0

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

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

Submission status: Wrong Answer

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

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

l = -1
r = 10**12

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

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

Submission status: Wrong Answer

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

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

l = -1
r = 10**12

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

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

Submission status: Wrong Answer

Solution code:
from numpy import*
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n,k=map(int,input().split())
    a=array(sorted(map(int,input().split())))
    b=array(sorted(map(int,input().split())))
    #print(a,b)
    ok=max(a)*max(b)
    ng=-1
    s=sum(a)
    def check(a,b,mid,k):
        if s-sum(minimum(a,mid//b))<=k:
            return 1
        else:
            return 0
            
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if check(a,b,mid,k):
            ok=mid
        else:
            ng=mid
    print(ok)

if __name__ == '__main__':
    main()