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:
from math import ceil
def ok(time,sum_A):
    #x =sum([ceil(time/f) for f in F])
    x =sum([(time//f) for f in F])
    
    if x >= sum_A -K:
        return True



#初期入力
N,K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

F.sort()
sum_A =sum(A)
bottom,top =0,max(A)*max(F)
while top -bottom >1:
    mid =(top +bottom)//2
    if ok(mid,sum_A):
        top =mid
    else:
        bottom =mid
if sum_A -K <= 0:
    print(0)
else:
    print(top)

Submission status: Wrong Answer

Solution code:
from math import ceil
def ok(time,sum_A):
    #x =sum([ceil(time/f) for f in F])
    x =sum([(time//f) for f in F])
    
    if x >= sum_A -K:
        return True



#初期入力
N,K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

sum_A =sum(A)
bottom,top =0,max(A)*max(F)
while top -bottom >1:
    mid =(top +bottom)//2
    if ok(mid,sum_A):
        top =mid
    else:
        bottom =mid
if sum_A -K <= 0:
    print(0)
else:
    print(top)

Submission status: Wrong Answer

Solution code:
from math import ceil
def ok(time,sum_A):
    #x =sum([ceil(time/f) for f in F])
    x =sum([(time//f) for f in F])
    
    if x >= sum_A -K:
        return True



#初期入力
N,K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

sum_A =sum(A)
bottom,top =0,max(A)*max(F)
while top -bottom >1:
    mid =(top +bottom)//2
    if ok(mid,sum_A):
        top =mid
    else:
        bottom =mid
if sum_A -K <= 0:
    print(bottom)
else:
    print(top)

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)
lef = -1
rig = 10*13

while rig - lef != 1:
    now = (rig + lef) //2
    cou = 0
    for i in range(n):
        t = now // f[i]
        cou += max(0,a[i]-t)
    if cou <= k:
        rig = now
    elif cou > k:
        lef = now
print(rig)

Submission status: Wrong Answer

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

if sum(A) >= K:
  print(0)
  exit()

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

def check(x):
  k = 0
  for a,f in zip(A, F):
    if a*f > x:
      while a > 0:
        a -= 1
        k += 1
        if a*f <= x: break

  return k <= K

ng,ok = 0, 10**18+1
while ok-ng > 1:
  x = (ok+ng)//2
  if check(x):
    ok = x
  else:
    ng = x

print(ok)

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    worst_score = 10 ** 12

    n, k = ns()
    a = na()
    f = na()
    a.sort()
    f.sort(reverse=True)
    score = [ai * fi for ai, fi in zip(a, f)]

    l = -1
    r = worst_score + 1

    while r - l > 1:
        middle = (l + r) // 2
        tmp_k = k
        for i in range(n):
            tmp = math.ceil((score[i] - middle) // f[i])
            tmp_k -= max(0, tmp)

            if tmp_k < 0:
                break

        if tmp_k >= 0:
            r = middle
        else:
            l = middle
            
    print(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def abc144_e():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
    F = np.array(input().split(), dtype=np.int64)
    A = np.sort(A)
    F = np.sort(F)[::-1]

    low = -1
    up = 10**12
    while up - low > 1:
        v = (up + low) // 2
        x = A - v // F
        if x.sum() > K:
            low = v
        else:
            up = v
    print(up)

if __name__ == '__main__':
    abc144_e()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
def sub(x):
    val = 0
    for aa,ff in zip(a,f):
        val += aa - (x//ff)
    return val<=k
if sub(0):
    ans = 0
else:
    l = 0
    r = sum(aa*ff for aa,ff in zip(a,f))
    while l+1<r:
        m = (l+r)//2
        if sub(m):
            r = m
        else:
            l = m
    ans = r
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    N, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())), reverse=True)
    F = sorted(list(map(int, input().split())))
    q = []
    for i in range(N):
        q.append((A[i]*F[i], A[i], F[i]))

    def isok(time):
        total = 0
        for t, a, f in q:
            acc = time / f
            if acc < a:
                total += a - acc
        return True if total <= K else False

    left = -1
    right = N+1
    while (right - left > 1):
        mid = left + (right - left) // 2
        if isok(mid):
            right = mid
        else:
            left = mid
    print(right)

    
if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    from math import floor
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N,K = LMIIS()
    A = LMIIS()
    F = LMIIS()


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


    def f(x):
        sum_diff = 0
        for a,f in zip(A,F):
            if a*f-x > 0:
                sum_diff += a-x//f
        return True if sum_diff <= K else False
    l = -10*13
    r = 10**13
    while r-l>1:

        m = (l+r)//2
        if f(m):
            r = m
        else:
            l = m
    print(r)











if __name__ == '__main__':
    main()

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

if k > sum(a):
    print(0)
    exit()

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

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

lb = -1
ub = a[0]*f[-1]

while ub - lb > 1:
    if (lb+ub) % 2 == 0:
        x = (lb+ub)//2
    else:
        x = (lb+ub)//2 + 1
    cx = np.full(n, x)
    ck = a - x//f
    ck = np.where(ck < 0, 0, ck)
    ck_sum = ck.sum()
    if ck_sum == k:
        break
    if ck_sum > k:
        lb = x
    else:
        ub = x
a_ck = a - ck
ans = a_ck * f
print(max(ans))

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

if k > sum(a):
    print(0)
    exit()

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

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

lb = -1
ub = a[0]*f[-1]

while ub - lb > 1:
    x = (lb+ub)//2
    cx = np.full(n, x)
    ck = a - x//f
    ck = np.where(ck < 0, 0, ck)
    ck_sum = ck.sum()
    if ck_sum == k:
        break
    if ck_sum > k:
        lb = x
    else:
        ub = x
a_ck = a - ck
ans = a_ck * f
print(max(ans))

Submission status: Wrong Answer

Solution code:
print(0)

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

if k > sum(a):
    print(0)
    exit()

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

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

lb = 0
ub = a[0]*f[-1]

while ub - lb > 1:
    x = (lb+ub)//2
    cx = np.full(n, x)
    ck = a - x//f
    ck = np.where(ck < 0, 0, ck)
    ck_sum = ck.sum()
    if ck_sum == k:
        break
    if ck_sum > k:
        lb = x
    else:
        ub = x
a_ck = a - ck
ans = a_ck * f
print(max(ans))

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,K = IL()
A = IL()
F = IL()
A.sort()
F.sort(reverse=True)

def is_ok(x):
  x = max(x,0)
  count = 0
  for i in range(N):
    count += A[i]-(x//F[i])
  if count<=K:
    return True
  else:
    return False

def meguru_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(meguru_bisect(-1,A[-1]*F[0]))

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,K = IL()
A = IL()
F = IL()
A.sort()
F.sort(reverse=True)

def is_ok(x):
  count = 0
  for i in range(N):
    count += A[i]-x//F[i]
  if count<=K:
    return True
  else:
    return False

def meguru_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

MAX = max(A[i]*F[i] for i in range(N))
print(meguru_bisect(-1,MAX))

Submission status: Wrong Answer

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

al.sort()
fl.sort(reverse=True)
afl = []
for a,f in zip(al,fl):
    afl.append((a,f))

ok, ng = 10**12, 0
while abs(ok-ng) > 1:
    mid = (ok+ng) // 2
    cnt = 0
    for a,f in afl:
        val = a*f
        train_cnt = (val-mid-1)//f + 1
        cnt += max(train_cnt, 0)

    if cnt <= k:
        ok = mid
    else:
    	ng = mid
print(ok)

Submission status: Wrong Answer

Solution code:
import copy
from heapq import heappop, heapify, heappush
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]
ans = 0
A.sort(reverse=True)
F.sort()
s = []
for i in range(N):
    s.append([A[i]*F[i], A[i], F[i]])
s.sort(reverse=True, key=lambda x: x[0])

def f(l, T):
    cur = 0
    num = 0
    S = copy.deepcopy(l)
    while cur <= K:
        if len(S) == 0:
            break
        a, b, c = S[num]
        a = -a
        if a <= T:
            break
        cur += math.ceil((a - T)/c)
        num += 1
    if cur <= K:
        return True
    else:
        return False

ok, ng = -s[0][0], -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if f(s, mid) == True:
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Wrong Answer

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

high = max(a)*max(b)
low = 0

while True:
    res = k
    if high < low:
        print(low)
        break
    mid = (low+high)//2
    for i in range(n):
        res -= -((-a[i]*b[i]+mid)//b[i])
    if res < 0:
        low = mid + 1
    if res >= 0:
        high = mid - 1

Submission status: Wrong Answer

Solution code:
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
A = inl()
F = inl()
A.sort()
F.sort(reverse=True)


def check(val):
    k = K
    for i in range(N):
        tmp = A[i] * F[i]
        dec = ((tmp - val) + F[i] - 1) // F[i]
        assert A[i] >= dec
        assert (A[i] - dec) * F[i] <= val
        k -= dec
        if k < 0:
            return False
    return True


def solve():
    if N == 1:
        return max(A[0] - K, 0) * F[0]

    ng, ok = -1, sum([A[i] * F[i] for i in range(N)])
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(solve())

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()

if k >= sum(a_list):
    print(0)
    exit()

point = []
for i in range(n):
    point.append(a_list[i] * f_list[i])

import math
def binary_search(point, k):
    left = 0
    right = 10 ** 12
    while left + 1< right:
        ans = 0
        center = (left + right) // 2
        for i in range(n):
            if point[i] > center:
                ans += a_list[i] - (center // f_list[i])
        if ans <= k:
            right = center
        else:
            left = center
    return left
    
value = binary_search(point, k)
print(value)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()

if k >= sum(a_list):
    print(0)
    exit()

point = []
for i in range(n):
    point.append(a_list[i] * f_list[i])

import math
def binary_search(point, k):
    left = 0
    right = 10 ** 12
    while left + 1< right:
        ans = 0
        center = (left + right) // 2
        for i in range(n):
            if point[i] > center:
                ans += a_list[i] - (center // f_list[i])
        if ans <= k:
            right = center
        else:
            left = center
    return center
    
value = binary_search(point, k)
print(value)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()

if k > sum(a_list):
    print(0)
    exit()

point = []
for i in range(n):
    point.append(a_list[i] * f_list[i])

import math
def binary_search(point, k):
    left = 0
    right = 10 ** 12
    while left + 1< right:
        ans = 0
        center = (left + right) // 2
        for i in range(n):
            if point[i] > center:
                ans += a_list[i] - (center // f_list[i])
        if ans <= k:
            right = center
        else:
            left = center
    return right    
    
value = binary_search(point, k)
print(value)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()

if k > sum(a_list):
    print(0)
    exit()

point = []
for i in range(n):
    point.append(a_list[i] * f_list[i])

import math
def binary_search(point, k):
    left = 0
    right = 10 ** 12
    while left + 1< right:
        ans = 0
        center = (left + right) // 2
        for i in range(n):
            if point[i] > center:
                ans += a_list[i] - math.floor(center / f_list[i])
        if ans <= k:
            right = center
        else:
            left = center
    return right    
    
value = binary_search(point, k)
print(value)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()

if k > sum(a_list):
    print(0)
    exit()

point = []
for i in range(n):
    point.append(a_list[i] * f_list[i])

import math
def binary_search(point, k):
    left = 0
    right = max(point)
    while left + 1< right:
        ans = 0
        center = (left + right) // 2
        for i in range(n):
            if point[i] > center:
                ans += a_list[i] - math.floor(center / f_list[i])
        if ans <= k:
            right = center
        else:
            left = center
    return right    
    
value = binary_search(point, k)
print(value)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()



point = []
for i in range(n):
    point.append(a_list[i] * f_list[i])

import math
def binary_search(point, k):
    left = 0
    right = max(point)
    while left + 1< right:
        ans = 0
        center = (left + right) // 2
        for i in range(n):
            if point[i] > center:
                ans += a_list[i] - math.floor(center / f_list[i])
        if ans <= k:
            right = center
        else:
            left = center
    return right    
    
value = binary_search(point, k)
print(value)

Submission status: Wrong Answer

Solution code:
import heapq
import math

n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort()
f_list.sort(reverse=True)

heap_list = []
for i in range(n):
    heap_list.append((-a_list[i] * f_list[i], f_list[i]))

heapq.heapify(heap_list)    
while k > 0:
    max_v, f = heapq.heappop(heap_list)
    if max_v == 0:
        break
    second_v, second_f = heap_list[1]    
    if max_v < second_v:
        max_v = - max_v
        second_v = - second_v
        c = math.ceil(second_v / f) - 1
        k -= max_v / f - c
        max_v = - c * f
    heapq.heappush(heap_list, (max_v, f))

max_v, f = heap_list[0]
print(-max_v)

Submission status: Wrong Answer

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,K = map(int,S().split())
A = LI()
F = LI()
a = sum(A)

if a <= K:
    print(0)
    exit()

left = 0
right = 10**12
while left + 1 < right:
    mid = (left + right) // 2
    if sum(mid//F[i] for i in range(N)) + K >= a:
        right = mid
    else:
        left = mid

print(right)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort()
f_list.sort(reverse=True)
for i in range(n):
    if a_list[i] >= k:
        a_list[i] -= k
        k = 0
        break
    elif a_list[i] < k:
        k = k - a_list[i]
        a_list[i] = 0
ans = 0
for i in range(n):
    ans += a_list[i] * f_list[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
  tmp=(a+b)//2
  c=sum([math.ceil(A[i]-tmp/F[i]) for i in range(N)])
  if c<=K:
    b=tmp
  else:
    a=tmp
print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
As = np.array(sorted(map(int, input().split())))
Fs = np.array(sorted(map(int, input().split()), reverse = True))

times = As * Fs

ng = -1
ok = np.amax(times)+1

while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    k = np.sum(np.ceil((times - mid) / Fs))
    if k > K:
        ng = mid
    else:
        ok = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
As = np.array(sorted(map(int, input().split())))
Fs = np.array(sorted(map(int, input().split()), reverse = True))

times = As * Fs

#めぐる式二分探索
ng = -1
ok = np.amax(times)

while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    k = np.sum(np.ceil((times - mid) / Fs))
    if k > K:
        ng = mid
    else:
        ok = mid

print(ok)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A_array = list(map(int, input().split()))
F_array = list(map(int, input().split()))

A_array.sort()
F_array.sort()
F_array = F_array[::-1]

X = 0
Y = 10 ** 12

while(Y - X > 1):
    mid = (X + Y) // 2
    # print(X, Y)
    k = 0
    for a, f in zip(A_array, F_array):
        m = mid // f
        # print(a, f, k)
        k += max(0, a - m)
    if k < K:
        Y = mid
    else:
        X = mid

print(Y)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A_array = list(map(int, input().split()))
F_array = list(map(int, input().split()))

A_array.sort()
F_array.sort()
F_array = F_array[::-1]

X = 0
Y = 10 ** 12

while(Y - X > 1):
    mid = (X + Y) // 2
    # print(X, Y)
    k = 0
    for a, f in zip(A_array, F_array):
        m = mid // f
        # print(a, f, k)
        k += max(0, a - m)
    if k <= K:
        Y = mid
    else:
        X = mid

print(Y)

Submission status: Wrong Answer

Solution code:
N,K=[int(s) for s in input().split()]
A=[int(s) for s in input().split()]
F=[int(s) for s in input().split()]
A.sort()
F.sort(reverse=1)


def success(x):
  suc_sum=0
  for i in range(N):
    a=x//F[i]
    if A[i]>a:
      suc_sum+=A[i]-a
  if suc_sum<=K:
    return True
  else:
    return False

def bisearch():
  bi_max=10**12
  bi_a=0
  bi_b=bi_max
  while bi_b-bi_a>1:
    c=(bi_a+bi_b)//2
    if success(c):
      bi_a,bi_b=[bi_a,c]
    else:
      bi_a,bi_b=[c,bi_b]
  return [bi_a,bi_b]

a,b=bisearch()
print(b)

Submission status: Wrong Answer

Solution code:
N,K=[int(s) for s in input().split()]
A=[int(s) for s in input().split()]
F=[int(s) for s in input().split()]
A.sort()
F.sort(reverse=1)
print(A)
print(F)

def success(x):
  suc_sum=0
  for i in range(N):
    a=x//F[i]
    if A[i]>a:
      suc_sum+=A[i]-a
  if suc_sum<=K:
    return True
  else:
    return False

def bisearch():
  bi_max=10**12
  bi_a=0
  bi_b=bi_max
  while bi_b-bi_a>1:
    c=(bi_a+bi_b)//2
    if success(c):
      bi_a,bi_b=[bi_a,c]
    else:
      bi_a,bi_b=[c,bi_b]
  return [bi_a,bi_b]

a,b=bisearch()
print(b)