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 fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7




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

    def ok(v):
        cnt = 0
        sa = 0
        for i in range(n):
            t = a[i]*f[i]
            if v - t >= 0:
                continue
            cnt += a[i] - (v // f[i])
            if cnt > k:
                break
        
        if cnt <= k:
            return True
        else:
            return False





    l, r = 0, 10 ** 19
    for i in range(50):
        m = (l + r) / 2
        if ok(m):
            r = m
        else:
            l = m
    print(int(m))

    
            
    

    

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

def cal(sum_, F, N, K, d):
    count = 0
    for i in range(N):
        if sum_[i] > d:
            count += math.ceil((sum_[i] - d) / F[i])
            if count > K:
                #作ることができない
                return False
    return True


def main():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    F = [int(i) for i in input().split()]
    A.sort()
    F.sort(reverse=True)
    sum_ = []
    for i in range(N):
        sum_.append(A[i] * F[i])

    right = 10 ** 12
    left = 0
    count = 0
    while left <= right:
        mid = (right + left) // 2
        if cal(sum_, F, N, K, mid):
            # midを小さくすることができる
            right = mid - 1
        else:
            # midを大きくしなければならない
            left = mid + 1
        count += 1
    print(mid)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import sys
from math import ceil

_HO = 2*10**5 * 10**6 + 1

def binary_search(lo=0,ho=_HO):
    if ho-lo==1: return lo

    mid = lo + (ho-lo-1)//2
    if check(mid):
        return binary_search(lo=lo,ho=mid+1)
    else:
        return binary_search(lo=mid+1,ho=ho)

def check(x):
    global k, a, f

    s = 0
    for ai, fi in zip(a,f):
        af = ai * fi
        if af<=x: continue
        s += ceil((af-x)/fi)
        if s>k: return False
    #
    return True

n,k = [ int(x) for x in sys.stdin.readline().strip().split() ]
a = [ int(x) for x in sys.stdin.readline().strip().split() ]
f = [ int(x) for x in sys.stdin.readline().strip().split() ]

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

print(binary_search())

Submission status: Wrong Answer

Solution code:
from sys import stdout
import heapq
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(t):
  #ddprint("foo {}".format(t))
  cnt = 0
  for j in range(n):
    v,i = b[j]
    #ddprint("c {} v {} i {}".format(cnt,v,i))
    if v<=t:
      return (cnt<=k)
    d = (v-t+f[i]-1)//f[i]
    cnt += d
    if cnt>k:
      return False
  return (cnt<=k)

n,k = inm()
a = inl()
f = inl()
a.sort()
f.sort(reverse=True)
b = [(f[i]*a[i], i) for i in range(n)]
b.sort(reverse=True)
mx = sum(a)
mn = -1
mid = mx
while mx>mn+1:
  mid = (mx+mn)//2
  if foo(mid):
    #ddprint("mid {} ok".format(mid))
    mx = mid
  else:
    #ddprint("mid {} ng".format(mid))
    mn = mid
print(mx)

Submission status: Wrong Answer

Solution code:
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

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

high = 0
for x,y in zip(a,f):
    high = max(high, x*y)
low = 0

if sum(a) < k:
    high = 0

while high > low + 1:
    mid = int(math.ceil((high + low) // 2))
    tmp = 0
    for x, y in zip(a,f):
        tmp += x - math.floor(mid / y)
        if tmp > k:
            low = mid
            break
    else:
        high = mid
print(high)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

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)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += -(-(A[i] * F[i] - s) // F[i])
    if ksum <= K:
        return True
    else:
        return False

lb = -1
ub = 10**13
while lb + 1 < ub:
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(ub)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))
time = [f[i] * a[-i-1] for i in range(n)]
print(time)

sup = max(time)
inf = 0
while sup > inf:
  x = (sup + inf) // 2
  train = sum([(max([0, time[i] - x]) + f[i] - 1) // f[i] for i in range(n)])
  print(x, train)
  if k < train:
    inf = x + 1
  else:
    sup = x
print(sup)

Submission status: Wrong Answer

Solution code:
import bisect
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

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

high = a[-1] * f[0]
low = 0

if sum(a) < k:
    high = 0

while high > low + 1:
    mid = int((high + low + 0.5) // 2)
    tmp = 0
    for x, y in zip(a,f):
        tmp += x - math.floor(mid / y)
        if tmp > k:
            low = mid
            break
    else:
        high = mid
print(high)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
left=1
right=10**12+1
while left<right:
    mid=(left+right)//2
    # print(mid)
    tmp=0
    for i in range(n):
        tmp+=max(0,A[i]-mid//F[i])
    if tmp>k:
        left=mid+1
    else:
        right=mid
print(mid)

Submission status: Wrong Answer

Solution code:
import bisect
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

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

high = a[-1] * f[-1] + 1
low = 0

if sum(a) < k:
    high = 0

while high > low + 1:
    mid = (high + low) // 2
    tmp = 0
    for x, y in zip(a,f):
        tmp += x - math.floor(mid / y)
        if tmp > k:
            low = mid
            break
    else:
        high = mid
print(high)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))
time = [f[i] * a[-i-1] for i in range(n)]

sup = max(time)
inf = 0
while sup > inf:
  x = (sup + inf) // 2
  if k < sum([(max([0, time[i] - x]) + f[i] - 1) // f[i] for i in range(n)]):
    inf = x + 1
  else:
    sup = x
print(x)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

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)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += -(-(A[i] * F[i] - s) // F[i])
    if ksum > K:
        return False
    else:
        return True

lb = -1
ub = 10**13
for i in range(100):
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(ub + 1)

Submission status: Wrong Answer

Solution code:
from sys import stdout
import heapq
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(t):
  #ddprint("foo {}".format(t))
  h = [x for x in h0]
  cnt = 0
  while len(h)>0:
    v,i = heapq.heappop(h)
    #ddprint("c {} v {} i {}".format(cnt,v,i))
    v = -v
    if v<=t:
      return (cnt<=k)
    d = max(0, (v-t+f[i]-1)//f[i])
    cnt += d
  return (cnt<=k)

n,k = inm()
a = inl()
f = inl()
a.sort()
f.sort(reverse=True)
h0 = []
for i in range(n):
    heapq.heappush(h0, (-f[i]*a[i], i))
#b = [f[i]*a[i] for i in range(n)]
#ddprint(a)
#ddprint(f)
#ddprint(b)
mx = sum(a)
mn = -1
mid = mx
while mx>mn+1:
  mid = (mx+mn)//2
  if foo(mid):
    #ddprint("mid {} ok".format(mid))
    mx = mid
  else:
    #ddprint("mid {} ng".format(mid))
    mn = mid
print(mx)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

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)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += -(-(A[i] * F[i] - s) // F[i])
    if ksum > K:
        return False
    else:
        return True

lb = -1
ub = 10**13
for i in range(100):
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(ub - 1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
left=0
right=10**12+1
while left<right:
    mid=(left+right)//2
    # print(mid)
    tmp=0
    for i in range(n):
        tmp+=max(0,A[i]-mid//F[i])
    if tmp>k:
        left=mid+1
    else:
        right=mid
print(mid)

Submission status: Wrong Answer

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_ and 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], 1]
    update_range = lambda mid: search_range.__setitem__(check(mid), mid)
    for _ in range(search_range[0].bit_length()+1):
        print(search_range)
        update_range(sum(search_range)//2)

    return -search_range[0]

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

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-int(x/f)
    if c > K:
        l = x
    else:
        r = x
print(r)

Submission status: Wrong Answer

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

Solution code:
from sys import stdout
import heapq
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(t):
  #ddprint("foo {}".format(t))
  h = []
  for i in range(n):
    heapq.heappush(h, (-f[i]*a[i], i))
  cnt = 0
  while len(h)>0:
    v,i = heapq.heappop(h)
    #ddprint("c {} v {} i {}".format(cnt,v,i))
    v = -v
    if v<=t:
      return (cnt<=k)
    d = max(0, (v-t+f[i]-1)//f[i])
    cnt += d
  return (cnt<=k)

n,k = inm()
a = inl()
f = inl()
a.sort()
f.sort(reverse=True)
#b = [f[i]*a[i] for i in range(n)]
#ddprint(a)
#ddprint(f)
#ddprint(b)
mx = sum(a)
mn = -1
mid = mx
while mx>mn+1:
  mid = (mx+mn)//2
  if foo(mid):
    #ddprint("mid {} ok".format(mid))
    mx = mid
  else:
    #ddprint("mid {} ng".format(mid))
    mn = mid
print(mx)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

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)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += -(-(A[i] * F[i] - s) // F[i])
    if ksum > K:
        return False
    else:
        return True

lb = -1
ub = 10**13
for i in range(100):
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(ub)

Submission status: Wrong Answer

Solution code:
import bisect

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)
if sum(A) <= K:
    print(0)
else:
    left = 0
    right = max([A[i]*F[i] for i in range(N)])
    while left + 1 != right:
        mid = int((left + right + 1) / 2)
        train_n = sum([A[i]-mid//F[i] for i in range(N)])
        if train_n > K:
            left = mid
        else:
            right = mid
    print(right)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

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)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += -(-(A[i] * F[i] - s) // F[i])
    if ksum > K:
        return False
    else:
        return True

lb = -1
ub = 10**12 
for i in range(50):
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(mid + 1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

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)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += -(-(A[i] * F[i] - s) // F[i])
    if ksum > K:
        return False
    else:
        return True

lb = -1
ub = 10**12 
for i in range(10):
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(mid + 1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

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)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += -(-(A[i] * F[i] - s) // F[i])
    if ksum > K:
        return False
    else:
        return True

lb = -1
ub = 10**12 
for i in range(100):
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(mid + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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


def judge(x):
    return dig - np.minimum(A, x // F).sum() <= K


l = 0
r = 10 ** 19

while l + 1 < r:
    test = (l + r) // 2
    if judge(test):
        r = test
    else:
        l = test

print(r)

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):
        #print(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:
            return bs(l, (m - l) // 2 + l, m)

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect

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)
if sum(A) <= K:
    print(0)
else:
    left = 0
    right = max([A[i]*F[i] for i in range(N)])
    while left + 1 != right:
        mid = int((left + right) / 2)
        train_n = sum([A[i]-mid//F[i] for i in range(N)])
        if train_n > K:
            left = mid
        else:
            right = mid
    print(right)

Submission status: Wrong Answer

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

a.sort()
f.sort()
a = a[::-1]
kaketa = []
for i in range(n):
    kaketa.append(a[i]*f[i])

left = 0
right = max(kaketa)

while True:
    jiku = (left+right)//2
    kaisuu = 0
    for i in range(n):
        if (kaketa[i] - jiku) % f[i] != 0:
            kaisuu += (kaketa[i] - jiku) // f[i] + 1
        else:
            kaisuu += (kaketa[i] - jiku) // f[i]
    if kaisuu > k:
        left = jiku
        bit = 0
    else:
        right = jiku
        bit = 1
    if right - left == 1:
        break

if sum(a) <= k:
    print(0)
else:
    print(right)

Submission status: Wrong Answer

Solution code:
import bisect

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)
if sum(A) <= K:
    print(0)
else:
    left = 0
    right = max([A[i]*F[i] for i in range(N)])
    while left + 1 != right:
        mid = int((left + right) / 2)
        train_n = sum([A[i]-int(mid/F[i]) for i in range(N)])
        if train_n > K:
            left = mid
        else:
            right = mid
    print(right)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

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)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += -(-(A[i] * F[i] - s) // F[i])
    if ksum > K:
        return False
    else:
        return True

lb = -10**18
ub = 10**18 
for i in range(100):
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(mid + 1)

Submission status: Wrong Answer

Solution code:
from sys import stdout
import heapq
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(t):
  ddprint("foo {}".format(t))
  h = []
  for i in range(n):
    heapq.heappush(h, (-f[i]*a[i], i))
  cnt = 0
  while len(h)>0:
    v,i = heapq.heappop(h)
    ddprint("c {} v {} i {}".format(cnt,v,i))
    v = -v
    if v<=t:
      return (cnt<=k)
    d = max(0, (v-t+f[i]-1)//f[i])
    cnt += d
  return (cnt<=k)

n,k = inm()
a = inl()
f = inl()
a.sort()
f.sort(reverse=True)
b = [f[i]*a[i] for i in range(n)]
ddprint(a)
ddprint(f)
ddprint(b)
mx = sum(a)
mn = -1
mid = mx
while mx>mn+1:
  mid = (mx+mn)//2
  if foo(mid):
    ddprint("mid {} ok".format(mid))
    mx = mid
  else:
    ddprint("mid {} ng".format(mid))
    mn = mid
print(mx)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

def ok(x):
    cnt = 0
    for i in range(N):
        current = A[i] * F[i]
        if current > x:
            cnt += -(-(current - x) // F[i])
            
    return cnt <= K

A.sort()
F.sort(reverse=True)
lb = 0
ub = 10 ** 12 + 1

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

Submission status: Wrong Answer

Solution code:
import math

def append2d(xn, x0):
  yn = []
  for i, x in enumerate(xn):
    if x[0] * x[1] < x0[0] * x0[1]:
      yn.append(x0)
      yn.extend(xn[i+1:])
      break
    else:
      yn.append(x)
  return yn
    
n, k = map(int, input().split())
an = list(map(int, input().split()))
fn = list(map(int, input().split()))
an.sort()
fn.sort(reverse=True)

fn_inv = [1.0 / f for f in fn]
alpha = (sum(an) - k) / sum(fn_inv)
fn_inv = [math.ceil(f * alpha) for f in fn_inv]
pn = [min(a, f) for (a, f) in zip(an, fn_inv)]

k_r = k - (sum(an) - sum(pn))
pn = sorted(zip(pn, fn), key=lambda x: x[0] * x[1], reverse=True)
pn = [[p[0], p[1]] for p in pn]
for _ in range(k_r):
  pn[0][0] -= 1
  pn = append2d(pn[1:], pn[0])
print(max([p[0] * p[1] for p in pn]))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import math
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)
B = [[A[i], F[i]] for i in range(N)]
t = A[N-1] * F[N-1]
B.sort(key=lambda x: x[0]*x[1])

for x in range(1, B[N-1][0]*B[N-1][1]):
    table = [0]*N
    for i in range(N):
        if B[i][0]*B[i][1] > x:
            k = x // B[i][1]
            table[i] = max(B[i][0] - k, 0)
    if sum(table) <= K:
        print(x)
        break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

@mt
def slv(N, K, A, F):
    A.sort(reverse=True)
    F.sort()

    def possible(c):
        k = K
        for a, f in zip(A, F):
            d = c//f
            k += d - a
        if k >= 0:
            return 1
        return 0
    
    b = Bisect(possible)
    return b.bisect_left(1, 0, 10**18)


def main():
    N, K = read_int_n()
    A = read_int_n()
    F = read_int_n()
    print(slv(N, K, A, F))


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.sort()
f.sort()
a = a[::-1]
kaketa = []
for i in range(n):
    kaketa.append(a[i]*f[i])

left = 0
right = max(kaketa)

while True:
    jiku = (left+right)//2
    kaisuu = 0
    for i in range(n):
        if (kaketa[i] - jiku) % f[i] != 0:
            kaisuu += (kaketa[i] - jiku) // f[i] + 1
        else:
            kaisuu += (kaketa[i] - jiku) // f[i]
    if kaisuu > k:
        left = jiku
        bit = 0
    else:
        right = jiku
        bit = 1
    if right - left == 1:
        break

if k == 0:
    print(right)
else:
    if bit == 1:
        print(left)
    else:
        print(right)

Submission status: Wrong Answer

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(reverse=True)
f_ls.sort()

l=-1
r=a_ls[0] * f_ls[-1]
while(l+1<r):
    c=(l+r)//2
    total = 0
    for i in range(n):
        a = a_ls[i] * f_ls[i] - c
        b = f_ls[i]
        total += (a+b-1)//b
    if total > k:
        l=c
    else:
        r=c
print(r)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

@mt
def slv(N, K, A, F):
    A.sort(reverse=True)
    F.sort()

    def possible(c):
        k = K
        for a, f in zip(A, F):
            d = c//f
            k -= a - d
        if k >= 0:
            return 1
        return 0
    
    b = Bisect(possible)
    return b.bisect_left(1, 0, 10**18)


def main():
    N, K = read_int_n()
    A = read_int_n()
    F = read_int_n()
    print(slv(N, K, A, F))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)
s = zip(a,f)

for ans in range(a[-1] * f[-1] + 1):
    tmp = 0
    for x, y in s:
        tmp += x - math.floor(ans / y)
    if tmp <= k:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
an = list(map(int, input().split()))
fn = list(map(int, input().split()))
an.sort()
fn.sort(reverse=True)

fn_inv = [1.0 / f for f in fn]
alpha = (sum(an) - k) / sum(fn_inv)
fn_inv = [math.ceil(f * alpha) for f in fn_inv]
pn = [min(a, f) for (a, f) in zip(an, fn_inv)]

k_r = k - (sum(an) - sum(pn))
pn = sorted(zip(pn, fn), key=lambda x: x[0] * x[1], reverse=True)
pn = [[p[0], p[1]] for p in pn]
for _ in range(k_r):
  pn[0][0] -= 1
  pn = sorted(pn, key=lambda x: x[0] * x[1], reverse=True)
print(max([p[0] * p[1] for p in pn]))