Problem:


Score: 500 points

Problem Statement

Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i.

In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows:

A team should assign one member to each food, and should not assign the same member to multiple foods.

It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish.

The score of a team is the longest time it takes for an individual member to finish the food.

Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total.

What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^{18}

1 \leq A_i \leq 10^6\ (1 \leq i \leq N)

1 \leq F_i \leq 10^6\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N
F_1 F_2 ... F_N

Output

Print the minimum possible score of the team.

Sample Input 1

3 5
4 2 1
2 3 1

Sample Output 1

2

They can achieve the score of 2, as follows:

Member 1 does 4 sets of training and eats Food 2 in (4-4) \times 3 = 0 seconds.

Member 2 does 1 set of training and eats Food 3 in (2-1) \times 1 = 1 second.

Member 3 does 0 sets of training and eats Food 1 in (1-0) \times 2 = 2 seconds.

They cannot achieve a score of less than 2, so the answer is 2.

Sample Input 2

3 8
4 2 1
2 3 1

Sample Output 2

0

They can choose not to do exactly K sets of training.

Sample Input 3

11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2

Sample Output 3

12



Sample input:
3 5
4 2 1
2 3 1


Sample output:
2

Submission status: Wrong Answer

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

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

ok = 10000000
ng = 0

while ok-ng>1:
    mid = ng + (ok-ng)//2
    trainings = 0
    for i in range(N):
        t = A[i]-mid//F[i]
        if t > 0:
            trainings += t
    if trainings <= K:
        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()))
F = list(map(int,input().split()))

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

ok = 10000000
ng = 0

while ok-ng>1:
    mid = (ok+ng)//2
    trainings = 0
    for i in range(N):
        t = A[i]-mid//F[i]
        if t > 0:
            trainings += t
    if trainings <= K:
        ok = mid
    else:
        ng = mid

trainings = 0
for i in range(N):
    t = A[i]-ng//F[i]
    if t > 0:
        trainings += t

if trainings<=K:
    print(ng)
else:
    print(ok)

Submission status: Wrong Answer

Solution code:
from math import ceil
import numpy as np
def main():
    N, K = map(int,input().split())
    A = np.array(list(map(int,input().split())), dtype=np.int16)
    C = np.array(list(map(int,input().split())), dtype=np.int16)
    A.sort()
    A = A[::-1]
    C.sort()
    def chk(x):
        cnt = 0
        for i in range(N):
            cnt += max(ceil(A[i]-x/C[i]), 0)
            if cnt > K:
                return False
        return True
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(m):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort(reverse=True)
    C.sort()
    def chk(x):
        cnt = 0
        for i in range(N):
            cnt += max(ceil(A[i]-x/C[i]), 0)
            if cnt > K:
                return False
        return True
    l, r = 0, 10**19
    while l < r:
        m = (l+r)//2
        if chk(m):
            r = m-1
        else:
            l = m+1
    l, r = min(l,r), max(l,r)
    for i in range(l-3, r+3):
        if chk(i):
            print(i)
            exit()
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort(reverse=True)
    C.sort()
    def chk(x):
        cnt = 0
        for a, c in zip(A, C):
            d = ceil(a-x/c)
            if d >= 0:
                cnt += d
            if cnt > K:
                return False
        return True
    l, r = 0, 2*10**17
    while l < r:
        m = (l+r)//2
        if chk(m):
            r = m-1
        else:
            l = m+1
    l, r = min(l,r), max(l,r)
    for i in range(l-3, r+3):
        if chk(i):
            print(i)
            exit()
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int,input().split())
A = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
C.sort()
def chk(x):
    cnt = 0
    for a, c in zip(A, C):
        d = ceil(a-x/c)
        if d >= 0:
            cnt += d
        if cnt > K:
            return False
    return True
l, r = 0, 2*10**17
while l < r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
l, r = min(l,r), max(l,r)
for i in range(l-3, r+3):
    if chk(i):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int,input().split())
A = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
C.sort()
def chk(x):
    cnt = 0
    for a, c in zip(A, C):
        d = ceil(a-x/c)
        if d >= 0:
            cnt += d
        if cnt > K:
            return False
    return True
l, r = 0, 10**19
while l < r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
l, r = min(l,r), max(l,r)
for i in range(l-3, r+3):
    if chk(i):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
from math import ceil
from bisect import bisect_left
N, K = map(int,input().split())
A = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
C.sort()
def chk(x):
    cnt = 0
    for a, c in zip(A, C):
        #print(a,c,ceil(a-x/c))
        d = ceil(a-x/c)
        if d >= 0:
            cnt += d
    return cnt <= K
l, r = 0, 10**19
while l < r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
l, r = min(l,r), max(l,r)
for i in range(l-3, r+3):
    if chk(i):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
from math import ceil
from bisect import bisect_left
N, K = map(int,input().split())
A = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
C.sort()
def chk(x):
    cnt = 0
    for a, c in zip(A, C):
        #print(a,c,ceil(a-x/c))
        d = ceil(a-x/c)
        if d >= 0:
            cnt += d
    return cnt <= K
l, r = 0, 10**19
while l < r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
l, r = min(l,r), max(l,r)
for i in range(r+3, l-3, -1):
    if chk(i):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
from math import ceil
from bisect import bisect_left
N, K = map(int,input().split())
A = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
C.sort()
def chk(x):
    cnt = 0
    for a, c in zip(A, C):
        #print(a,c,ceil(a-x/c))
        d = ceil(a-x/c)
        if d >= 0:
            cnt += d
    return cnt <= K
l, r = 0, 10**19
while l < r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
l, r = min(l,r), max(l,r)
if chk(r):
    print(r)
else:
    print(l)

Submission status: Wrong Answer

Solution code:
#map(int, input().split())
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)
ans = 0
# print(A, F)
for i in range(N):
    if K > 0:
        eat = min(A[i], K)
        K -= eat
        A[i] -= eat
    ans += A[i] * F[i]
print(ans)

Submission status: Wrong Answer

Solution code:

from math import ceil
N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
sum_A = sum(A)
if K >= sum_A:
    print(0)
    exit()
AFC = [(A[i], F[i], A[i]*F[i]) for i in range(N)]
AFC.sort(key=lambda x: x[2])

def is_ok(x):
    rest = K
    #最大コストをx以下にできるか
    for i in range(N):
        a, f, cost = AFC[i]
        need = ceil((cost - x)/f)
        rest -= need
    if rest >= 0:
        return True
    else:
        return False

left = 0
right = 10**12 + 100

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
F_list = list(map(int, input().split()))

A_list_min = sorted(A_list)
F_list_max = sorted(F_list, reverse=True)

first_OK = 10**12

def is_ok(arg):
    check_cnt = 0
    return_flag = 0
    for i in range(N):
        check_cnt += A_list_min[i] - arg//F_list_max[i]
    if check_cnt <= K:
        return_flag = 1
    else:
        return_flag = 0
    return return_flag

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

print(bisect(-1, first_OK))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
hito=list(map(int,input().split()))
meshi=list(map(int,input().split()))

hito.sort()
meshi.sort(reverse=True)

S_hito=sum(hito)

def check(x):
    kari=0
    for i in range(N):
        kari+=min(hito[i],x/meshi[i])
    if S_hito<=kari+K:
        return True
    else:
        return False

l=-1
r=10**13
while l+1<r:
    mid=(l+r)//2
    if check(mid):
        r=mid
    else:
        l=mid
print(r)

Submission status: Wrong Answer

Solution code:
from math import ceil
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()
lot = []
for k in range(N):
  lot.append((A[k]*F[k], k))
lot.sort(key =  lambda x:x[0],reverse=True)
high = lot[0][0]
#print('A:', A)
#print('F:', F)
#print(lot)
def binary_search(high):
  low = 0
  mid = (low + high) //2
  while low < high:
    final = False
    mid = (low + high) //2
    if low == high-1:
      final = True
    #print(low, high, mid)
    res = K
    flag = True
    for k in range(N):
      if res < 0:
        flag = False
        break
      else:
        if lot[k][0] <= mid:
          break
        else:
          res -= ceil((lot[k][0]-mid)/F[lot[k][1]])
          continue
    #print(flag)
    if flag:
      high = mid
    else:
      if final:
        mid += 1
      low = mid
    #print(low, high, mid)
  #return None
  return mid

print(binary_search(high))

Submission status: Wrong Answer

Solution code:
from math import ceil
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()
lot = []
for k in range(N):
  lot.append((A[k]*F[k], k))
lot.sort(key =  lambda x:x[0],reverse=True)
high = lot[0][0]
#print('A:', A)
#print('F:', F)
#print(lot)
def binary_search(high):
  low = 0
  mid = (low + high) //2
  while low <= high:
    mid = (low + high) //2
    #print(low, high, mid)
    res = K
    flag = True
    for k in range(N):
      if res < 0:
        flag = False
        break
      else:
        if lot[k][0] <= mid:
          break
        else:
          res -= ceil((lot[k][0]-mid)/F[lot[k][1]])
          continue
    #print(flag)
    if flag:
      high = mid-1
    else:
      low = mid+1
 
  #return None
  return mid

print(binary_search(high)+1)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
mF = F[-1]
portion = [F[-1]//F[k] for k in range(N)]


#print('A:', A)
#print('F:', F)
#print('portion:', portion)
lot = [0 for _ in range(N)]


sa = sum(A) - K
sp = sum(portion)
for k in range(N):
  point = sa*portion[k]//sp
  if point > A[k]:
    lot[k] += A[k]*F[k]
    A[k] = 0
  else:
    lot[k] += point *F[k]
    A[k] -= point
res = sum(A) - K


#print(lot)
#print(A)
#print(res)
if res == 0:
  print(max(lot))
  exit()
foo = []
finish = 0
for k in range(N):
  if A[k] == 0:
    finish = max(finish, lot[k])
    continue
  else:
    foo.append((lot[k]+F[k], A[k], F[k]))

from heapq import heapify, heappop, heappush
heapify(foo)
while res>0:
  res -= 1
  item = heappop(foo)
  if item[1] == 1:
    finish = max(finish, item[0])
    continue
  else:
    heappush(foo, (item[0]+item[2], item[1]-1, item[2]))
  #print(foo)

print(max(item[0], finish))

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 K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
from math import gcd
def lcm(x, y):
  return (x*y)//gcd(x, y)

f_lcm = 1
for k in range(N):
  f_lcm = lcm(f_lcm, F[k])

portion = [f_lcm//F[k] for k in range(N)]


#print('A:', A)
#print('F:', F)
#print('portion:', portion)
lot = [0 for _ in range(N)]


sa = sum(A) - K
sp = sum(portion)
for k in range(N):
  point = sa*portion[k]//sp
  if point > A[k]:
    lot[k] += A[k]*F[k]
    A[k] = 0
  else:
    lot[k] += point *F[k]
    A[k] -= point
res = sum(A) - K
if res > 10**8:
  print('TLE')

#print(lot)
#print(A)
#print(res)
if res == 0:
  print(max(lot))
  exit()
foo = []
finish = 0
for k in range(N):
  if A[k] == 0:
    finish = max(finish, lot[k])
    continue
  else:
    foo.append((lot[k]+F[k], A[k], F[k]))

from heapq import heapify, heappop, heappush
heapify(foo)
while res>0:
  res -= 1
  item = heappop(foo)
  if item[1] == 1:
    finish = max(finish, item[0])
    continue
  else:
    heappush(foo, (item[0]+item[2], item[1]-1, item[2]))
  #print(foo)

print(min(item[0], finish))

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 K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
from math import gcd
def lcm(x, y):
  return (x*y)//gcd(x, y)

f_lcm = 1
for k in range(N):
  f_lcm = lcm(f_lcm, F[k])

portion = [f_lcm//F[k] for k in range(N)]


#print('A:', A)
#print('F:', F)
#print('portion:', portion)
lot = [0 for _ in range(N)]


sa = sum(A) - K
sp = sum(portion)
for k in range(N):
  point = sa*portion[k]//sp
  if point > A[k]:
    lot[k] += A[k]*F[k]
    A[k] = 0
  else:
    lot[k] += point *F[k]
    A[k] -= point
res = sum(A) - K
if res > 10**6:
  sa = sum(A) - K
  for k in range(N):
    point = sa*portion[k]//sp
    if point > A[k]:
      lot[k] += A[k]*F[k]
      A[k] = 0
    else:
      lot[k] += point *F[k]
      A[k] -= point
res = sum(A) - K

if res > 10**7:
  print('TLE')

#print(lot)
#print(A)
#print(res)
if res == 0:
  print(max(lot))
  exit()
foo = []
finish = 0
for k in range(N):
  if A[k] == 0:
    finish = max(finish, lot[k])
    continue
  else:
    foo.append((lot[k]+F[k], A[k], F[k]))

from heapq import heapify, heappop, heappush
heapify(foo)
while res>0:
  res -= 1
  item = heappop(foo)
  if item[1] == 1:
    finish = max(finish, item[0])
    continue
  else:
    heappush(foo, (item[0]+item[2], item[1]-1, item[2]))
  #print(foo)

print(min(item[0], finish))

Submission status: Wrong Answer

Solution code:
import math

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


def is_ok(x):
    cnt = 0
    for i in range(N):
        cnt += A[i] - math.floor(x / F[i])
    return cnt <= K


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

ans = meguru_bisect(-1, max([a*f for a, f in zip(A, F)]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')

    @cc.export('is_ok', '(u8[:],u8[:],u8,u8)')
    def is_ok(A, F, x, k):
        tmp = 0
        for a, f in zip(A, F):
            y = a * f
            if y > x:
                tmp += a - x // f
        return tmp <= k

    cc.compile()
    exit(0)

from my_module import is_ok
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)
F = np.sort(F)[::-1]

ok = 9 * (10 ** 11)
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(A, F, mid, k):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')

    @cc.export('is_ok', '(u8[:],u8[:],u8,u8)')
    def is_ok(A, F, x, k):
        tmp = 0
        for a, f in zip(A, F):
            y = a * f
            if y > x:
                tmp += a - x // f
        return tmp <= k

    cc.compile()
    exit(0)

from my_module import is_ok
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)
F = np.sort(F)[::-1]

ok = 6 * (10 ** 11)
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(A, F, mid, k):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')

    @cc.export('is_ok', '(u8[:],u8[:],u8,u8)')
    def is_ok(A, F, x, k):
        tmp = 0
        for a, f in zip(A, F):
            y = a * f
            if y > x:
                tmp += a - x // f
        return tmp <= k

    cc.compile()
    exit(0)

from my_module import is_ok
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)
F = np.sort(F)[::-1]

ok = 3 * (10 ** 11)
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(A, F, mid, k):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')

    @cc.export('is_ok', '(u8[:],u8[:],u8,u8)')
    def is_ok(A, F, x, k):
        tmp = 0
        for a, f in zip(A, F):
            y = a * f
            if y > x:
                tmp += a - x // f
        return tmp <= k

    cc.compile()
    exit(0)

from my_module import is_ok
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)
F = np.sort(F)[::-1]

ok = 10 ** 11
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(A, F, mid, k):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import math

def can(X):
    training = 0
    for i in range(N):
        training += max(math.ceil(A[i] - X / F[i]), 0)
    return training <= K

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

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

a = -1
b = max(A) * max(F) * N
c = 0

while (b - a) >= 1:
    c = (a + b) / 2
    if can(c):
        b = c
    else:
        a = c

res = math.floor(c)

if can(res):
    print(res)
else:
    print(res + 1)

Submission status: Wrong Answer

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

def check(x):
  r = 0
  for i in range(n):
    r += (max(0,(a[i]*f[i]-x))+(f[i]-1))//f[i]
  #print(r, x)
  if r<=k:
    return True
  else:
    return False
ok = 10**12
ng = 0
while ok-ng>1:
  mid = (ok + ng)//2
  if check(mid):
    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()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)

def check(x):
  r = 0
  for i in range(n):
    r += (a[i]*f[i]-x+(f[i]-1))//f[i]
  if r<=k:
    return True
  else:
    return False
ok = 10**12
ng = 0
while ok-ng>1:
  mid = (ok + ng)//2
  if check(mid):
    ok = mid
  else:
    ng = mid
print(ok)

Submission status: Wrong Answer

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

OK = 10**12
NG = -1

while OK-NG > 1:
    mid = (OK+NG)//2
    cnt = 0
    for a, f in zip(A, F):
        cnt += (a*(f+1)-1-mid)//a
    if cnt <= K:
        OK = mid
    else:
        NG = mid
    # print('OK:{}, NG:{}, cnt:{}'.format(OK, NG, cnt))

print(OK)

Submission status: Wrong Answer

Solution code:

#test

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

A.sort()
F.sort(reverse=True)
AF = [A[i]*F[i] for i in range(N)]

l = 0
r = max(AF)

while r-l > 1:
    x = (l+r)//2
    k =0
    #スコアをx以下にするのに必要な最小コストを算出
    for i in range(N):
        if AF[i]<=x:
            continue
        else:
            k += A[i]-x//F[i]
    if k <= K:
        r = x
    else:
        l=x

print(r)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
abilities=sorted(list(map(int,input().split())))
foods=sorted(list(map(int,input().split())),reverse=True)

if sum(abilities)<=k:
  print(0)
  exit()
  
def check(score):
  ret=0
  for a,f in zip(abilities,foods):
    ret+=(a*f-score+f-1)//f
  return ret<=k

ok=10**12+1
ng=0
for _ in range(50):
  mid=(ok+ng)//2
  if check(mid):
    ok=mid
  else:
    ng=mid
print(ok)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
abilities=sorted(list(map(int,input().split())))
foods=sorted(list(map(int,input().split())),reverse=True)

if sum(abilities)<=k:
  print(0)
  exit()
  
def check(score):
  ret=0
  for a,f in zip(abilities,foods):
    ret+=(a*f-score+f-1)//f
  return ret<=k

ok=10**12
ng=0
for _ in range(50):
  mid=(ok+ng)//2
  if check(mid):
    ok=mid
  else:
    ng=mid
print(ok)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = map(int, input().split())
f = map(int, input().split())
a = sorted(a)
f = sorted(f)[::-1]


def c(x):
    # x決めると必要な修行回数も決まる
    res = 0
    for O, K in zip(a, f):
        d = max(0, O * K - x)
        res += (d + K - 1) // K
    return res <= k


l = -1
r = 1 << 60
while r != l:
    mid = (l + r) >> 1
    if c(mid):
        r = mid
    else:
        l = mid + 1
print(r)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = map(int, input().split())
f = map(int, input().split())
a = sorted(a)
f = sorted(f)[::-1]


def c(x):
    # x決めると必要な修行回数も決まる
    res = 0
    for O, K in zip(a, f):
        if O * K > x:
            d = O * K - x
            res += (d + K - 1) // K
    return res <= k


l = -1
r = 1 << 60
while r != l:
    mid = (l + r) >> 1
    if c(mid):
        r = mid
    else:
        l = mid + 1
print(r)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = map(int, input().split())
f = map(int, input().split())
a = sorted(a)
f = sorted(f)[::-1]


def c(x):
    # x決めると必要な修行回数も決まる
    res = 0
    for i in range(n):
        tmp = a[i] * f[i]
        if tmp > x:
            d = tmp - x
            res += (d + f[i] - 1) // f[i]
    return res <= k


l = -1
r = 1 << 60
while r != l:
    mid = (l + r) >> 1
    if c(mid):
        r = mid
    else:
        l = mid + 1
print(r)

Submission status: Wrong Answer

Solution code:
def is_good(mid, key):
    ret = 0
    for i in range(N):
        ret += A[i] - mid // F[i]
    return ret <= key


def binary_search(key):
    bad, good = -1, 10 ** 18
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


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

Submission status: Wrong Answer

Solution code:
from sys import stdin

input = stdin.readline

def main():
    N, K = map(int, input().rstrip().split())
    A = list(map(int, input().rstrip().split()))
    F = list(map(int, input().rstrip().split()))
    A.sort()
    F.sort(reverse=True)
    l = -1
    r = 10 ** 12
    while(r - l > 1):
        c = (l + r) // 2
        def ok():
            s = 0
            for i in range(N):
                s += max((A[i] - (c / F[i])), 0)
            return s <= K
        if ok():
            r = c
        else:
            l = c
    print(r)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

input = stdin.readline

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)
    l = -1
    r = 10 ** 12
    while(r - l > 1):
        c = (l + r) // 2
        def ok():
            s = 0
            for i in range(N):
                s += max((A[i] - (c / F[i])), 0)
            return s <= K
        if ok():
            r = c
        else:
            l = c
    print(r)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
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)

left=0
right=10**12+1
ans=float("INF")
while True:
    mid=(left+right)//2

    now=0
    for i in range(N):
        if F[i]*A[i]>mid:
            now+=ceil(((F[i]*A[i])-mid)/F[i])
    #print(now, mid)
    if now==K:
        ans=min(ans, mid)
        break
    elif now>K:
        if left==mid:
            break
        left=mid
    else:
        if right==mid:
            break
        right=mid
        ans=min(ans, mid)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
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)

left=0
right=10**12+1
ans=float("INF")
while True:
    mid=(left+right)//2
    if mid==left or mid==right:
        break
    now=0
    for i in range(N):
        if F[i]*A[i]>mid:
            now+=ceil(((F[i]*A[i])-mid)/F[i])
    #print(now, mid)
    if now==K:
        ans=min(ans, mid)
        break
    elif now>K:
        left=mid
    else:
        right=mid
        ans=min(ans, mid)

print(ans)

Submission status: Wrong Answer

Solution code:
N, K  = map(int, input().split())
A = list(map(int, input().split()))
F = list( map(int, input().split()))
A.sort()
F.sort(reverse=True)
print(A)
print(F)
la = 10**12+1
sm = -1
while sm+1<la:
    mi = (sm+la)//2
    y=0
    for i in range(N):
        y += max(0, A[i]-(mi//F[i]))
    if y<=K:
        la = mi
    else:
        sm = mi
print(la)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N,K=map(int,input().split())
A=np.array(input().split(),dtype=int)
F=np.array(input().split(),dtype=int)

A=np.sort(A)
F=np.sort(F)[::-1]

X=A*F

low=0
high=np.max(X)

while low<high-1:
    mid=(low+high)//2
    a=A-mid//F
    a=a[a>0].sum()
    
    if a==K:
        print(mid)
        sys.exit()
        
    elif a<K:
        high=mid
    else:
        low=mid

print(high)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N,K=map(int,input().split())
A=np.array(input().split(),dtype=int)
F=np.array(input().split(),dtype=int)

A=np.sort(A)
F=np.sort(F)[::-1]

X=A*F

low=0
high=np.max(X)

while low<=high:
    mid=(low+high)//2
    a=np.sum(np.floor(A-mid//F))
    
    if a==K:
        print(mid)
        sys.exit()
        
    elif a<K:
        high=mid-1
    else:
        low=mid+1

print(mid)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N,K=map(int,input().split())
A=np.array(input().split(),dtype=int)
F=np.array(input().split(),dtype=int)

A=np.sort(A)
F=np.sort(F)[::-1]

X=A*F

low=0
high=np.max(X)

while low<=high:
    mid=(low+high)//2
    a=np.sum(np.floor(A-mid//F))
    
    if a==K:
        print(mid)
        sys.exit()
        
    elif a<K:
        high=mid
    else:
        low=mid

print(high+1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N,K=map(int,input().split())
A=np.array(input().split(),dtype=int)
F=np.array(input().split(),dtype=int)

A=np.sort(A)
F=np.sort(F)[::-1]

X=A*F

low=0
high=np.max(X)

while low<=high:
    mid=(low+high)//2
    a=np.sum(np.floor(A-mid//F))
    
    if a==K:
        print(mid)
        sys.exit()
        
    elif a<K:
        high=mid-1
    else:
        low=mid+1

print(high+1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N,K=map(int,input().split())
A=np.array(input().split(),dtype=int)
F=np.array(input().split(),dtype=int)

A=np.sort(A)
F=np.sort(F)[::-1]

X=A*F

low=0
high=np.max(X)

while low<=high:
    mid=(low+high)//2
    a=np.sum(A-mid//F)
    
    if a==K:
        print(mid)
        sys.exit()
        
    elif a>K:
        high=mid-1
    else:
        low=mid+1

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([(a*f-time)/f for a,f in zip(A,F) if a*f -time >0])
    
    if x <= K:
        #print(x,time)
        return True



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

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

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

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