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: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))[::-1]
Cs = [a*b for a, b in zip(As, Bs)]
BCs = list(zip(Bs, Cs))

def func(target):
    r = 0
    for b, c in BCs:
        r += math.ceil(max(0, c - target) / b)
    return r <= K

if __name__ == '__main__':
    min_i, max_i, index = -1, max(Cs)+1, 1
    if func(min_i) or not func(max_i):
        3/0
    while True:
        if func(index):
            index, max_i = (index-1 + min_i)//2, index-1
            continue
        index, min_i = (index+1 + max_i)//2, index+1
        if min_i > max_i:
            print(min_i)
            break

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))[::-1]
Cs = [a*b for a, b in zip(As, Bs)]
BCs = list(zip(Bs, Cs))

def func(target):
    r = 0
    for b, c in BCs:
        r += math.ceil(max(0, c - target) / b)
    return r <= K

if __name__ == '__main__':
    min_i, max_i, index = 0, max(Cs)+1, 1
    if func(min_i) or not func(max_i):
        3/0
    while True:
        if func(index):
            index, max_i = (index-1 + min_i)//2, index-1
            continue
        index, min_i = (index+1 + max_i)//2, index+1
        if min_i > max_i:
            print(min_i)
            break

Submission status: Runtime Error

Solution code:
lass Contest:
    def __init__(self, member_cost,food_cost,k):
        self.member_cost = member_cost
        self.food_cost   = food_cost
        self.max_training_times = k
        
    def canAchieve(self,target):
        sum_training_times = 0
        for i in range(len(self.member_cost)):
            sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i])

        return  sum_training_times <= self.max_training_times
        


    def bisect(self,begin,end):
        if (end - begin <= 1 ):
            return end
        target = (begin + end)//2
        if self.canAchieve(target):
            return self.bisect(begin,target)

        else:
            return self.bisect(target,end)




def resolve():
    n,k  = map(int,input().split())
    
    member_cost = list(map(int,input().split()))

    food_cost = list(map(int,input().split()))
    member_cost.sort()
    food_cost.sort(reverse=True)
    total_cost = []
    for i in range(len(member_cost)):
        total_cost.append(member_cost[i]*food_cost[i])

    max_total_cost = max(total_cost)
    contest = Contest(member_cost,food_cost,k)
    print(contest.bisect(-1,max_total_cost))
    
resolve()

Submission status: Runtime Error

Solution code:
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=-1
    right=10**12
    prev_x=-10
    while True:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
        if abs(next_x-prev_x)<=1:
            break
        prev_x=next_x
    print(answer)

main()

Submission status: Runtime Error

Solution code:
import sys
n, k = map(int, input().split())
l=list(map(int, input().split()))
f=list(map(int, input().split()))
if sum(l)<=k:
    print(0)
    sys.exit()
ans=int(0)
l.sort()
f.sort()
f.reverse()


ok=int(l[n-1]*f[0])
ng=int(0)
while True:
    a=int(0)
    mid=int((ok + ng)//2)
    if ok-ng<=1:
        break

    for i in range(n):
        if mid//f[i]<l[i]:
            c +=l[i]-mid//f[i]


    if c<=k:
        ok=mid

    else:
        ng=mid

print(ok)

Submission status: Runtime Error

Solution code:
import sys
n, k = map(int, input().split())
l=list(map(int, input().split()))
f=list(map(int, input().split()))
if sum(l)<=k:
    print(0)
    sys.exit()
ans=int(0)
l.sort()
f.sort()
f.reverse()


ok=int(l[n-1]*f[0])
ng=int(0)
while True:
    a=int(0)
    mid=int((ok + ng)//2)
    if ok-ng<=1:
        break

    for i in range(n):
        if mid//f[i]<l[i]:
            c +=l[i]-mid//f[i]


    if a>=sum(l)-k:
        ok=mid

    else:
        ng=mid

print(ok)

Submission status: Runtime Error

Solution code:
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=0
    right=10**12
    prev_x=-10
    while True:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
        if abs(next_x-prev_x)<=1:
            break
        prev_x=next_x
    print(answer)

main()

Submission status: Runtime Error

Solution code:
import sys
n, k = map(int, input().split())
l=list(map(int, input().split()))
f=list(map(int, input().split()))
if sum(l)<=k:
    print(0)
    sys.exit()
ans=int(0)
l.sort()
f.sort()
f.reverse()
m=l[0]*f[0]

ok=int(l[n]*f[0])
ng=int(0)
while True:
    a=int(0)
    mid=int((ok + ng)//2)
    if ok-ng==1:
        break

    for i in range(n):
        if mid//f[i]<=l[i]:
            a +=mid//f[i]
        else:
            a += l[i]

    if a>=sum(l)-k:
        ok=mid
        ans=ng
    else:
        ng=mid
        ans=ok
print(ans)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
a_ls=list(map(int,input().split()))
f_ls=list(map(int,input().split()))

a_ls.sort()
f_ls.sort()
f_ls.reverse()

def can_eat_by(x):
    cost_after_training=list(map(lambda item: x//item, f_ls))
    sum=0
    for i in range(N):
        if a_ls[i]>cost_after_training[i]:
            sum+=a_ls[i]-cost_after_training[i]
    return sum<=K

left=0
right=10**12
prev_x=-10
while True:
    next_x=(right+left)//2
    if can_eat_by(next_x):
        answer=next_x
        right=next_x
    else:
        left=next_x
    if abs(next_x-prev_x)<=1:
        break
    prev_x=next_x
print(answer)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
import heapq
import math

def main():
    N, K = map(int, input().split())
    A = [int(c) for c in input().split()]
    F = [int(c) for c in input().split()]
    
    A.sort()
    F.sort(reverse=True)

    num = 0
    sum_ = A * F
    left = 0
    right = 10 ** 12
    while(num < 50):
        number = 0
        mid = (left + right) // 2
        # print(mid)
        for i in range(len(A)):
            if sum_[i] <= mid:
                continue
            else:
                number += math.ceil((sum_[i] - mid) / F[i])
            # print(number)
        if number > K:
            # 最大値をmidより小さくできない -> 最大値はもっとでかい
            left = mid + 1
        else:
            right = mid
        num += 1
    print(mid)
                

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=map(int,input().split())
f=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: Runtime Error

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 is_ok(t):
  cost = 0
  for aa,ff in zip(a,f):
    temp = t // ff
    if temp >= aa:
      contninue
    cost += aa - temp
    if cost > k:
      return False
  return True
left = 0
right = a[-1]*f[0]+1
while left < right:
  mid = (left + right) // 2
  if is_ok(mid):
    right = mid
  else:
    left = mid + 1
print(left)

Submission status: Runtime Error

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 is_ok(t):
  cost = 0
  for aa,ff in zip(a,f):
    temp = t // ff
    if temp >= aa:
      contninue
    cost += aa - temp
  if cost <= k:
    return True
  return False
left = 0
right = a[-1]*f[0]
while left < right:
  mid = (left + right) // 2
  if is_ok(mid):
    right = mid
  else:
    left = mid + 1
print(left)

Submission status: Runtime Error

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

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

left = -1
right = A[-1] * F[0]
while left+1 < right:
    mid = int(left + (right-left)//2)
    if isOk(mid):
        right = mid
    else:
        left = mid
print(right)n,k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

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

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

Submission status: Runtime Error

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: Runtime Error

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]
C=[]
for i in range(N):
  C.append(B[i]*G[i])

def dfs(t):
  if t==K:
    print(max(C))
  else:
    n=C.index(max(C))
    C[n]-=G[n]
    dfs(t+1)

if sum(A) <= K:
  print(0)
else:
  dfs(0)

Submission status: Runtime Error

Solution code:
k,*t=[map(int,t.split())for t in open(0)]
A,F=map(sorted,t)
o=10**12
g=-1
while~g+o:
 m,l=o+g>>1,k[1]
 for a,f in zip(A,F[::-1]):l-=max(0,a-m//f)
 if l<0:g=m
 else:o=m
print(o)

Submission status: Runtime Error

Solution code:
n,k,*a=map(int,open(0).read().split())
z=sorted(a[:n]),sorted(a[n:])[::-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: Runtime Error

Solution code:
// g++ -std=c++14 submit.cpp
// #define INF 9223372036854775807

# include <bits/stdc++.h>
// # define INF 1e9 + 1
using namespace std;

int main(){
  long int N, K;
  cin >> N >> K;
  vector<long int> A, F;
  long int v;

  long int tot = 0;
  for(int i=0; i<N; i++){
    cin >> v;
    A.push_back(v);
    tot += v;
  }

  if(tot <= K){
    cout << 0 << endl;
    exit(0);
  }

  for(long int i=0; i<N; i++){
    cin >> v;
    F.push_back(v);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(F.begin(), F.end());

  long int l, r;
  l = 0;
  vector<long int> B;
  for(long int i=0; i<N; i++) {
    B.push_back(A[i] * F[i]);
    r = max(r, A[i]*F[i]);
  }

  long int ans = 1e12;

  while(l < r){
    long int m = (l+r) / 2;
    long int count = 0;
    for(long int i=0; i<N; i++){
      if(B[i] - m > 0){
        count += (B[i] - m) / F[i];
        if((B[i] - m) % F[i] != 0) count++;
      }
    }

    if(count <= K){
      ans = min(ans, m);
      if(r == m+1) break;
      r = m+1;
    } else {
      if(l == m-1) break;
      l = m-1;
    }
  }
  cout << ans << endl;

}

Submission status: Runtime Error

Solution code:
import numpy as np

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

maxaf=a[0]*f[0]
for i in range(n):
	if a[i]*f[i]>maxaf:
		maxaf=a[i]*f[i]

def solve(x):
	total=0
	for i in range(n):
		total+=max(0,a[i]-x//f[i]) #負になりうる懸念ができていなかった、とほほ
	return total<=k

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

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

Submission status: Runtime Error

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

maxaf=a[0]*f[0]
for i in range(n):
	if a[i]*f[i]>maxaf:
		maxaf=a[i]*f[i]

def solve(x):
	total=0
	for i in range(n):
		total+=max(0,a[i]-x//f[i]) //負になりうる懸念ができていなかった、とほほ
	return total<=k

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

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

Submission status: Runtime Error

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

maxaf=a[0]*f[0]
for i in range(n):
	if a[i]*f[i]>maxaf:
		maxaf=a[i]*f[i]

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

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

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

Submission status: Runtime Error

Solution code:
INPUT
3 5
4 2 1
2 3 1
OUTPUT
2
INPUT
3 8
4 2 1
2 3 1
OUTPUT
0
INPUT
11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2
OUTPUT
12

n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    h+=max(a[i]-(mid//f[i]), 0)
  if h<=k:ok=mid
  else:ng=mid
print(ok)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
 
def isEaten(x):
    temp = 0
    for i in range(N):
        t = x // F[i]
        if t < A[i]:
            temp += (A[i] - t)
    return temp <= K:
 
 
def bitSearch(r, l):
    m = (r+l) // 2
    if m == l:
        if isEaten(l):
            print(l)
        else:
            print(r)
        exit()
    elif isEaten(m):
        bitSearch(m, l)
    else:
        bitSearch(r, m)
 
 
target = max([A[i]*F[i] for i in range(N)])
bitSearch(target, 0)

Submission status: Runtime Error

Solution code:
import numpy as np

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

Asum = sum(A)

Asort = sorted(A)
Fsort = sorted(F,reverse=True)

def test(x):
    res = max(0,Asort-x//Fsort).sum()
    return res <= K

left = -1
right = 10**13

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

ans = right

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

n, k = map(int, input().split())
a = np.sort(np.array(input().split(), dtype=np.int))
f = np.sort(np.array(input().split(), dtype=np.int))
time = f * a[::-1]

sup = time.max()
inf = 0
while sup > inf:
  x = (sup + inf) // 2
  train = ((time[time > x] - x + f - 1) // f).sum()
  if k < train:
    inf = x + 1
  else:
    sup = x
print(sup)

Submission status: Runtime Error

Solution code:
import math


def binSearch(N, A, key):
    left = 0
    right = N - 1
    k = (left + right) // 2
    while True:
        if key(A[k]):
            right = k
        else:
            left = k
        _k = (left + right) // 2
        if _k == k:
            return right
        else:
            k = _k


def judge(N, K, x, MAF):
    n = 0
    for m, a, f in MAF:
        if m > x:
            n += math.ceil((m - x) / f)
        if n > K:
            return False
    return True


def calc(N, K, A, F):
    if N == 1:
        return max((A[0] - K) * F[0], 0)
    A.sort()
    F = sorted(F, key=lambda x: -x)
    maxm = -10 ** 13
    MAF = []
    for i in range(N):
        t = (A[i] * F[i], A[i], F[i])
        maxm = max(maxm, t[0])
        MAF += [t]
    return binSearch(maxm + 1, list(range(maxm + 1)), lambda x: judge(N, K, x, MAF))


(N, K) = tuple([int(s) for s in input().split()])
A = [int(s) for s in input().split()]
F = [int(s) for s in input().split()]
print(calc(N, K, A, F))

Submission status: Runtime Error

Solution code:
import math
import heapq


def binSearch(N, A, key):
    left = 0
    right = N - 1
    k = (left + right) // 2
    while True:
        print((k, left, right))
        if key(A[k]):
            right = k
        else:
            left = k
        _k = (left + right) // 2
        if _k == k:
            return right
        else:
            k = _k


def judge(N, K, x, MAF):
    n = 0
    for m, a, f in MAF:
        if m > x:
            n += math.ceil((m - x) / f)
        if n > K:
            return False
    return True


def calc(N, K, A, F):
    if N == 1:
        return max((A[0] - K) * F[0], 0)
    A.sort()
    F = sorted(F, key=lambda x: -x)
    maxm = -10 ** 13
    MAF = []
    for i in range(N):
        t = (A[i] * F[i], A[i], F[i])
        maxm = max(maxm, t[0])
        MAF += [t]
    return binSearch(maxm + 1, list(range(maxm + 1)), lambda x: judge(N, K, x, MAF))


(N, K) = tuple([int(s) for s in input().split()])
A = [int(s) for s in input().split()]
F = [int(s) for s in input().split()]
print(calc(N, K, A, F))

Submission status: Runtime Error

Solution code:
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
m=0
a=np.array(a)
f=np.array(f)
for i in range(n):
    m=max(m,a[i]*f[i])
x=m//2
l=0
r=m
def check(x):
    x=np.array([x]*n)
    p=np.sum(np.max(0,a-x//f))
    if p>k:
        return False
    else:
        return True
while l<r:
    if check(x):
        r=x
        x=(r+l)//2
    else:
        l=x
        x=(r+l)//2
print(r)

Submission status: Runtime Error

Solution code:
from heapq import *
def abc144c():
  n,k=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  f=sorted(list(map(int,input().split())))[::-1]
  q=[] 
  for i,j in zip(a,f):
    heappush(q,(-i*j,j))
  for i in range(k):
    tmp,key=heappop(q)
    heappush(q,(tmp+key,key))
  ans,key=-heappop(q)
  print(ans)
abc144c()

Submission status: Runtime Error

Solution code:
from heapq import *
def abc144c():
  n,k=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  f=sorted(list(map(int,input().split())))[::-1]
  q=[] 
  for i,j in zip(a,f):
    heappush(q,(-i*j,j))
  for i in range(k):
    tmp,key=heappop(q)
    heappush(q,(tmp+key,key))
  ans,key=-heappop(q)
  return ans
print(abc144c())

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
import heapq
import numpy as np
import math

def main():
    N, K = map(int, input().split())
    A = [int(c) for c in input().split()]
    F = [int(c) for c in input().split()]
    
    A.sort()
    F.sort(reverse=True)

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

    num = 0
    sum_ = A * F
    left = 0
    right = 10 ** 12
    while(num < 90):
        number = 0
        mid = (left + right) // 2
        # print(mid)
        for i in range(len(A)):
            if sum_[i] <= mid:
                continue
            else:
                number += math.ceil((sum_[i] - mid) / F[i])
            # print(number)
        if number > K:
            # 最大値をmidより小さくできない -> 最大値はもっとでかい
            left = mid + 1
        else:
            right = mid
        num += 1
    print(mid)
                
        



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import ceil
from heapq import heappush, heappop, heapreplace

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))
    F = sorted(map(int, input().split()), reverse=1)
    level = {}
    hq = []
    hqv = set()
    for a,f in zip(A,F):
        if -a*f not in hqv:
            heappush(hq, -a*f)
            hqv.add(-a*f)
            level[-a*f] = [f]
        else:
            level[-a*f].append(f)

    def check(X):
        hq_, K_, level_ = hq[:], K, level.copy()
        while hq_[0] < X:
            c = heappop(hq_)
            lc = level_.pop(c)
            K_ -= sum(ceil((X-c)/f) for f in lc)
            if K_ < 0:
                return 1
        return 0

    search_range = [hq[0], 0]
    update_range = lambda mid: search_range.__setitem__(check(mid), mid)
    for _ in range(search_range[0].bit_length()):
        update_range(sum(search_range)//2)

    return -search_range[0]

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

Submission status: Runtime Error

Solution code:
def abc144c():
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  f=list(map(int,input().split()))
  a.sort(reverse=True);f.sort()

  from heapq import *
  q=[]
  for i,j in zip(a,f):
    heappush(q,(-i*j,str(j)))
  for i in range(k):
    temp,key=heappop(q)
    heappush(q,(temp+int(key),key))
  ans,key=heappop(q)
  print(-ans)

abc144c()

Submission status: Runtime Error

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

_n, _k = map(int, input().split())
_a = input()[:-1]
_f = input()[:-1]
alist = [item for item in _a]
flist = [item for item in _f]


def chker(costs, diffs, max_k):
    if sum(costs) <= max_k:
        print(0)

    costs.sort()
    diffs.sort(reverse=True)
    sclist = [(item1, item2, item1 * item2) for item1, item2 in zip(costs, diffs)].sort(key=lambda x:x[2], reverse=True)
    k = max_k
    while k > 0:
        k -= 1
        sclist[0][0] = sclist[0][0] - 1
        if sclist[0][0] == 0:
            sclist = sclist[1:]
        else:
            sclist[0][2] = sclist[0][0] * sclist[0][1]
            sclist.sort(key=lambda x:x[2], reverse=True)

    print(sclist[0][2])


chker(alist, flist, _k)

Submission status: Runtime Error

Solution code:
def reduction(A,k):
    num_minus = 0
    A.sort(reverse=True)
    B=A[:]
    B.append(0)
    for i in range(len(B)):
        diff=B[i]-B[i+1]
        tot_diff=(i+1)*diff
        if num_minus+tot_diff >= k:
            break
        else:
            num_minus += tot_diff
    for j in range(i):
        B[j]=B[i]
    for j in range(i-(k-num_minus)+1,i+1):
        B[j]=B[j]-1
    B=B[:-1]
    return B


N,K=map(int,input().split())
A=[int(x) for x in input().split()]
F=[int(x) for x in input().split()]
if K>=sum(A):
    print(0)
else:
    A = reduction(A,K)
    F.sort()
    T=[]
    for i in range(len(A)):
        T.append(A[i]*F[i])
    print(max(T))

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))
A = np.sort(A)[::-1]
F = np.sort(F)
# 二部探索法　Aの最大値をどこまで減らせるか
if A.sum() <= K:
    print(0)
    exit()
if K == 0:
    print((A * F).max())
up = (A * F).max() # 可能 mid は完食にかかる時間
low = 0 # 不可能
while up > low + 1:
    mid = (up + low) // 2
    if (A - min(A, (mid // F))).sum() <= K: #可能
        up = mid
    else:
        low = mid
print(up)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
l=0
r=10**12
m=(r+l)//2
def check(x):
    p=0
    for i in range(n):
        if x//f[i]<a[i]:
            p+=a[i]-x//f[i]
            if p>k:
                return False
    if p>k:
        return False
    else:
        return True
while l<r:
    if check(x):
        r=x
        x=(r+l)//2
    else:
        l=x
        x=(r+l)//2
print(r)

Submission status: Runtime Error

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
for i in range(N):
    cost[i]=A[i]*F[i]
cost_add=np.argsort(cost)
i=-1
shugyou=0
if K<sum[A]:
        
    for _ in range(K):
        add=cost_add[-1]
        cost[add]-=F[add]
        for i in range(1,N):
            if cost[cost_add[-i]]<cost[cost_add[-1-i]]:
                m=cost_add[-i]
                cost_add[-i]=cost_add[-1-i]
                cost_add[-1-i]=m
            else:
                break
    print(cost[cost_add[-1]])

else:
    print('0')

Submission status: Runtime Error

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

    flag = 0

    ls = [ x*y for (x, y) in zip(a, f)]
    ls = [[ls[i], i] for i in range(n)]

    ls.sort(reverse=True)

    suma = sum(a)

    while k != 0:
        if k < suma:
            k -= 1
            a[ls[0][1]] -= 1
            ls[ls[0][1]] -= f[ls[0][1]]
            ls.sort(reverse=True)
        else:
            flag = 1
            break
    
    if flag == 1:
        ans = 0
    else:
        ans = ls[0][0]

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

    flag = 0

    ls = [ x*y for (x, y) in zip(a, f)]
    ls = [[ls[i], i] for i in range(n)]

    ls.sort(reverse=True)

    suma = sum(a)

    while k != 0:
        if k < suma:
            k -= 1
            a[ls[0][1]] -= 1
            ls[ls[0][1]] -= f[ls[0][1]]
            ls.sort(reverse=True)
        else:
            flag == 1
            break
    
    if flag = 1:
        ans = 0
    else:
        ans = ls[0][0]

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N,K=map(int, input().split())
A = (int(i) for i in input().split())
F = (int(i) for i in input().split())
list.sort(A, reverse=True)
list.sort(F, reverse=True)
idx = 0
while(K>0):
    if K >= A[idx]:
        K = K - A[idx]
        A[idx] = 0
    else:
        A[idx] = A[idx] - K
        K = 0
sm = 0
for i in range(N):
    sm = A[i] * F[i]
print(sm)

Submission status: Runtime Error

Solution code:
import bisect

n, k = [int(x) for x in input().split()]
xs   = [int(x) for x in input().split()]
fs   = [int(x) for x in input().split()]

ys   = sorted(xs)
xs.sort()
fs.sort(reverse = True)

y = xs[-1]
i = n - 1
j = 0

while 0 < k and 0 <= y:
	i = j
	j = bisect.bisect_left(xs, y)
	if 0 < j:
		a = min(k, (xs[j] - xs[j - 1]) * (n - j))
		b = a // (n - j)
		y = xs[j - 1]
	else:
		a = min(k, xs[j])
		b = k // n
		y = -1
	k = k - b - (a % (n - j))

x = xs[i]
#print(i, j, a, b, k)
for z in range(i, n):
	xs[z] = x
for z in range(j, n):
	xs[z] -= b
for z in range(0, k):
	xs[z + j] -= 1
	
r = 0

for i in range(0, n):
	r = max(r, fs[i] * xs[i])

print(r/2)

Submission status: Runtime Error

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

ans = 0

if K > sum(A):
    ans = 0
else:
    t = b
    b = sum(A) - K
    for i in range(b):
        t -= A[i]
        if t <= 0:
            u = i
            break
    
    ans = A[u] * F[u]
print(ans)