Problem:


Score: 500 points

Problem Statement

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

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

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

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

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

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

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

Constraints

All values in input are integers.

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

0 \leq K \leq 10^{18}

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

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the minimum possible score of the team.

Sample Input 1

3 5
4 2 1
2 3 1

Sample Output 1

2

They can achieve the score of 2, as follows:

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

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

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

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

Sample Input 2

3 8
4 2 1
2 3 1

Sample Output 2

0

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

Sample Input 3

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

Sample Output 3

12



Sample input:
3 5
4 2 1
2 3 1


Sample output:
2

Submission status: Wrong Answer

Solution code:
import math

n,k = map(int, input().split())
lstA = list(map(int, input().split()))
lstF = list(map(int, input().split()))

lstA.sort()
lstF.sort()
lstF.reverse()

def check(x):
    checker = 0
    for i in range(n):
        checker += math.ceil(lstA[i]-x/lstF[i])
    if checker <= k:
        return True
    else:
        return False

left = -1
right = 10**12+1

while left <= right:
    center = (left+right)//2
    if check(center) == True:
        right = center
    else:
        left = center
    if right <= left+1:
        print(right)
        exit()

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 = 10**12
ng = -1

while ok-ng>1:
  X = (ok+ng)//2
  tmp = 0
  for i,e in enumerate(A):
    tmp += max(e-X/F[i],0)
  if tmp<=K:
    ok = X
  else:
    ng = X
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 = 10**12
ng = -1

while ok-ng>1:
  X = (ok+ng)//2
  tmp = 0
  for i in range(N):
    tmp += max(A[i]-X/F[i],0)
  if tmp<=K:
    ok = X
  else:
    ng = X
print(ok)

Submission status: Wrong Answer

Solution code:
import math

n,k = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
f = list(map(int, input().strip().split()))
a.sort()
f.sort()
#f = f[::-1]
af = []
r = 0
for i in range(n):
	af.append([a[n-1-i]*f[i], f[i]])
	r = max(r, af[i][0])

#r = af[0][0]
l = 0
while l < r:
	c = (l+r)//2
	training = 0
	for e in af:
		if c > e[0] or k < training:
			break
		training += (e[0]-c + e[1]-1) // e[1]
	if training <= k:
		r = c
	else:
		l = c+1
print(l)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    sum_a = sum(a)
    f = list(map(int, input().split()))
    f.sort()
    right = a[0]*f[0]
    left = 0
    while right > left:
        middle = (right + left)//2
        b = 0
        
        for i in range(n):
            b += min(a[i], middle//f[i])
        if sum_a - b <= k:
            right = middle
        else:
            left = middle + 1

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

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    f = list(map(int, input().split()))
    f.sort()
    right = a[0]*f[0]
    left = 0
    while right > left:
        middle = (right + left)//2
        b = 0
        
        for i in range(n):
            b += max(0, a[i]-(middle//f[i]))
        if b <= k:
            right = middle
        else:
            left = middle + 1

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

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    f = list(map(int, input().split()))
    f.sort()
    right = 10**12
    left = 0
    while right > left:
        middle = (right + left)//2
        b = 0
        for i in range(n):
            b += max(0, a[i]-(middle//f[i]))
        if b == k:
            right = middle
            break
        elif b < k:
            right = middle
        else:
            left = middle + 1
    print(right)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    f = list(map(int, input().split()))
    f.sort()
    right = a[0] * f[0]
    left = 0
    while right > left:
        middle = (right + left)//2
        b = 0
        for i in range(n):
            b += max(0, a[i]-(middle//f[i]))
        if b == k:
            right = middle
            break
        elif b < k:
            right = middle
        else:
            left = middle + 1
    print(right)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
# a = [int(x) for x in input().split()]
# f = [int(x) for x in input().split()]
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
lx = 0
rx = a[-1] * f[0]
while(rx-lx>1):
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        kk += max(0, a[j] - cx//f[j])
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().split())
# a = [int(x) for x in input().split()]
# f = [int(x) for x in input().split()]
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
lx = 0
rx = a[-1] * f[0]
while(rx-lx>1):
    cx = (lx + rx) // 2
    kk = 0
    for j in range(n):
        ta = a[j]
        y = (ta*f[j] - cx + f[j] -1) // f[j]
        kk += max(0, y)
    if kk <= k:
        rx = cx
    else:
        lx = cx
print(rx)

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()
a = a[::-1]
left = -1
right = np.max(a * f)
while left + 1 < right:
    mid = (left + right) // 2
    print(np.sum(np.maximum(a - mid // f, 0)))
    if np.sum(np.maximum(a - mid // f, 0)) <= k:
        right = mid
    else:
        left = 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(reverse=True)
#print(a)
#print(f)
scale = 10
aim = 2 ** scale -1
gap = 2 ** (scale-1)
while True:
  train = 0
  for i in range(n):
    train += max(0, a[i] - aim//f[i])
  if gap == 0:
    if train <= k:
      print(aim)
    else:
      print(aim+1)
    break
  #print(aim,gap,train)
  if train <= k:
    aim -= gap
    gap //= 2
  else:
    aim += gap
    gap //= 2

Submission status: Wrong Answer

Solution code:
from math import ceil
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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

low = 0
high = A[-1]*F[0]

while low <= high:
    mid = (low+high)//2
    train = K
    for a, f in zip(A, F):
        if a*f > mid:
            need_train = ceil((a*f-mid)/f)
            if train >= need_train:
                train -= need_train
            else:
                low = mid+1
                break
    else:
        high = mid-1
print(mid)

Submission status: Wrong Answer

Solution code:
from math import ceil
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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

low = 0
high = A[-1]*F[0]

while low <= high:
    mid = (low+high)//2
    train = K
    for a, f in zip(A, F):
        if a*f > mid:
            need_train = ceil((a*f-mid)/a)
            if train >= need_train:
                train -= need_train
            else:
                low = mid+1
                break
    else:
        high = mid-1
print(mid)

Submission status: Wrong Answer

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

if sum(A) < K:
    K = sum(A)

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

left = 0
right = 10 ** 12
while left < right:
    mid = (left + right) // 2
    sum = 0
    G = A - (mid / F)
    if G[G>0].sum() <= K:
        right = mid
    else:
        left = mid + 1

print(right)

Submission status: Wrong Answer

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

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k:
      right = mid
    else:
      left = mid

print(left)

Submission status: Wrong Answer

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

AF = [A[i] * F[i] for i in range(N)]
big = max(AF)
small = 0
x = 0

while big - small > 2:
    x = (big + small) // 2
    cnt = 0
    for i in range(N):
        cnt += max(A[i] - x//F[i], 0)
    if cnt < K:
        small = x
    elif cnt > K:
        big = x
    else:
        print(x)
        exit()

cnt = 0
for i in range(N):
    cnt += max(A[i] - small//F[i], 0)
if cnt <= K:
  print(small)
else:
  print((big + small)//2)

Submission status: Wrong Answer

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

AF = [A[i] * F[i] for i in range(N)]
big = max(AF)
small = 0
x = 0

while big - small > 1:
    x = (big + small) // 2
    cnt = 0
    for i in range(N):
        cnt += max(A[i] - x//F[i], 0)
    if cnt < K:
        small = x
    elif cnt > K:
        big = x
    else:
        print(x)
        exit()

print(x)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  _, k = map(int, input().split())
  a_vals = list(map(int, input().split()))
  a_sum = sum(a_vals) - k
  f_vals = list(map(int, input().split()))
  f_rates = [(1 / v) for v in f_vals]
  f_sum = sum(f_rates)

  if a_sum < 1:
    print(0)
    return

  a_vals = [v / f_sum for v in f_rates]
  l_rate = 0
  h_rate = a_sum * 4

  for _ in range(100):
    rate = (l_rate + h_rate) * 0.5
    costs = sum(int(v * rate) for v in a_vals)

    if costs > a_sum:
      h_rate = rate
    elif costs < a_sum:
      l_rate = rate
    else:
      h_rate = rate
      l_rate = rate
      break

  print(max(int(v * h_rate) * f for v, f in zip(a_vals, f_vals)))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  _, k = map(int, input().split())
  a_vals = list(map(int, input().split()))
  a_sum = sum(a_vals) - k
  f_vals = list(map(int, input().split()))
  f_rates = [(1 / v) for v in f_vals]
  f_sum = sum(f_rates)

  if a_sum < 1:
    print(0)
    return

  a_vals = [v / f_sum for v in f_rates]
  l_rate = a_sum
  h_rate = a_sum * 10

  for _ in range(400):
    rate = (l_rate + h_rate) * 0.5
    costs = sum(int(v * rate) for v in a_vals)

    if costs > a_sum:
      h_rate = rate
    elif costs < a_sum:
      l_rate = rate
    else:
      h_rate = rate
      l_rate = rate
      break

  print(max(int(v * h_rate) * f for v, f in zip(a_vals, f_vals)))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  _, k = map(int, input().split())
  a_vals = list(map(int, input().split()))
  a_sum = sum(a_vals) - k
  f_vals = list(map(int, input().split()))
  f_rates = [(1 / v) for v in f_vals]
  f_sum = sum(f_rates)

  if a_sum < 1:
    print(0)
    return

  a_vals = [v / f_sum for v in f_rates]
  l_rate = a_sum
  h_rate = a_sum * 4

  for _ in range(100):
    rate = (l_rate + h_rate) * 0.5
    costs = sum(int(v * rate) for v in a_vals)

    if costs > a_sum:
      h_rate = rate
    elif costs < a_sum:
      l_rate = rate
    else:
      h_rate = rate
      l_rate = rate
      break

  print(max(int(v * h_rate) * f for v, f in zip(a_vals, f_vals)))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  _, k = map(int, input().split())
  a_vals = list(map(int, input().split()))
  a_sum = sum(a_vals) - k
  f_vals = list(map(int, input().split()))
  f_rates = [(1 / v) for v in f_vals]
  f_sum = sum(f_rates)

  if a_sum < 1:
    print(0)
    return

  a_vals = [v / f_sum for v in f_rates]
  l_rate = a_sum
  h_rate = a_sum * 2

  for _ in range(100):
    rate = (l_rate + h_rate) * 0.5
    costs = sum(int(v * rate) for v in a_vals)

    if costs > a_sum:
      h_rate = rate
    elif costs < a_sum:
      l_rate = rate
    else:
      h_rate = rate
      l_rate = rate
      break

  print(max(int(v * h_rate) * f for v, f in zip(a_vals, f_vals)))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  _, k = map(int, input().split())
  a_vals = list(map(int, input().split()))
  a_sum = sum(a_vals) - k
  f_vals = list(map(int, input().split()))
  f_rates = [(1 / v) for v in f_vals]
  f_sum = sum(f_rates)

  if a_sum < 1:
    print(0)
    return

  a_vals = [v / f_sum for v in f_rates]
  l_rate = a_sum
  h_rate = a_sum * 2

  for _ in range(50):
    rate = (l_rate + h_rate) * 0.5
    costs = sum(int(v * rate) for v in a_vals)

    if costs > a_sum:
      h_rate = rate
    elif costs < a_sum:
      l_rate = rate
    else:
      h_rate = rate
      l_rate = rate
      break

  print(max(int(v * h_rate) * f for v, f in zip(a_vals, f_vals)))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np


def main():
    s = input().split(" ")
    N = int(s[0])
    K = int(s[1])
    A = np.array([int(a) for a in input().split(" ")])
    F = np.array([int(a) for a in input().split(" ")])
    A = np.sort(A)
    F = np.sort(F)[::-1]
    AF = A * F
    m = np.max(AF)

    if(func(0, AF, F, N, K)):
        print(0)
        return
    a = 0
    b = m
    for aaa in range(m):
        if((b - a) <= 1):
            print(b)
            return
        mid = int((b - a) / 2.) + a
        if(func(mid, AF, F, N, K)):
            b = mid
        else:
            a = mid
    print("???????")


def func(saidai, AF, F, N, K):
    count = np.sum((AF[(AF - saidai) > 0] - saidai) // F[(AF - saidai) > 0])
    return count <= K


if(__name__ == "__main__"):
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse = True)

P = [A[i]*F[i] for i in range(n)]

def b(p):
    result = 0
    for i in range(n):
        result += A[i] - p / F[i]
    return result

x0 = 0
xn = max(P)

if sum(A) <= k: print('0')
else:    
    while xn - x0 > 1:
        x = (xn - x0) / 2 + x0
        b0 = b(x)
        if b0 > k: x0 = x
        else: xn = x
    if xn % 1 == 0: print(int(xn))
    else: print(int(xn // 1) + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N, train_max = map(int, input().split())
members = np.sort(list(map(int, input().split())))
members_sum = members.sum()
foods = np.sort(list(map(int, input().split())))[::-1]

inferenced_time_max = int(1e+6 * 1e+6)
inferenced_time_min = -1
inferenced_time = None

while inferenced_time_max > inferenced_time_min+1:
  inferenced_time = (inferenced_time_max + inferenced_time_min) // 2
  inferenced_members = np.minimum(members, inferenced_time // foods)
  if members_sum - inferenced_members.sum() <= train_max:
    inferenced_time_max = inferenced_time
  else:
    inferenced_time_min = inferenced_time

print(inferenced_time)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, train_max = map(int, input().split())
members = np.sort(list(map(int, input().split())))
members_sum = members.sum()
foods = np.sort(list(map(int, input().split())))[::-1]

inferenced_time_max = int(1e+6 * 1e+6)
inferenced_time_min = 1

while inferenced_time_max > inferenced_time_min + 1:
  inferenced_time = (inferenced_time_max + inferenced_time_min) // 2
  inferenced_members = np.minimum(members, inferenced_time // foods)
  if members_sum - inferenced_members.sum() <= train_max:
    inferenced_time_max = inferenced_time
  else:
    inferenced_time_min = inferenced_time

print(inferenced_time_max)

Submission status: Wrong Answer

Solution code:
(_,K),*T=[sorted(map(int,t.split()))for t in open(0)]
d=[2**40,0]
exec("i=sum(d)//2;d[sum(max(0,a-i//b)for a,b in zip(T[0],T[1][::-1]))>K]=i;"*41)
print(d[0])

Submission status: Wrong Answer

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

if sum(A) < K:
    K = sum(A)

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

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

print(right)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import bisect
import numpy as np

def Main(N, K, A, F):
    A.sort()
    F.sort()
    for i in range(K):
        mx = A.pop()-1
        bisect.insort_right(A, mx)
        if(mx < 0):
            break
    A.sort(reverse=True)
    a = np.array(A)
    f = np.array(F)
    return max(a*f)

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    print(Main(N, K, A, F))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import bisect
import numpy

def Main(N, K, A, F):
    A.sort()
    F.sort()
    for i in range(K):
        mx = A.pop()-1
        bisect.insort_right(A, mx)
        if(mx < 0):
            break
    A.sort(reverse=True)
    a = numpy.array(A)
    f = numpy.array(F)
    return max(a*f)

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    print(Main(N, K, A, F))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
w=[0,0]
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=32
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<a[i]-ws//f[i]:
            p=-1
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws//f[i]
    if p>=0:
        w[1]=ws
    else:
        w[0]=ws
print(w[1])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
w=[0,0]
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
#print(w)
x=50
while x>0:
    x-=1
    ws=(w[0]+w[1]+1)//2
    p=k
    #print(ws)
    for i in range(n):
        if a[i]*f[i]>ws and p<a[i]-ws//f[i]:
            p=-1
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws//f[i]
    #print(x,ws,p)
    if p>=0:
        w[1]=ws
    else:
        w[0]=ws
    #print(w)
#print(w)
print(w[1])

Submission status: Wrong Answer

Solution code:
import sys
import bisect

n, k = map(int, input().split())
a = sorted([int(x) for x in input().split()])
f = sorted([int(x) for x in input().split()])

c = [a[i]*f[n-i-1] for i in range(n)]

border = c[n-1]
idx = n-1
for i in range(n-2, -1, -1): # n-2から0まで
    if border >= c[i]:
        border -= border - c[i]
        a[idx] -= (a[idx]-a[i])
        idx=i
    else:
        a[i] -= (c[i]-border)//f[n-i-1] + (0 if (c[i]-border)%f[n-i-1]==0 else 1)

c = [a[i]*f[n-i-1] for i in range(n)]
print(max(c))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
w=[0,0]
ans=0
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=80
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<ws/f[i]-a[i]:
            w[0]=ws
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws/f[i]
    if p>0:
        w[1]=ws
    else:
        w[0]=ws
print(w[1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

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)
w=[0,0]
ans=0
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=80
while x>0:
    x-=1
    ws=(w[0]+w[1]+1)//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<ws/f[i]-a[i]:
            w[0]=ws
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws/f[i]
    if p>0:
        w[1]=ws
    else:
        w[0]=ws
print(w[1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
s = A.sum()
l = -1
r = (10**6)*2+1
# 全てのa*fが答えとなる数以下にできるかを10**12から二分探索
while l+1 < r:
    m = (l+r) // 2 # こここそが二分探索の肝で、ありえん小さい数とありえん大きい数から始めて半分にして狭めていく
    # 全てのA、Fにつき、Aとm//Fで小さい方の合計がK以下
    # m//Fは修行したあとの消化コスト
    # mが大きすぎてnp.minimum(A, m//F)がすべてAを選ぶならその合計は0なのでK以下が成り立つ
    # その場合、r=mとしてrを減らして再計算
    # K以下は修行に余力を残した状態か、修行できてないか。それより上のmはありえないのでr = mとする
    if s - np.minimum(A, m//F).sum() <= K:
        r = m
    # 修行ポイント以上に修行してしまった場合、それ未満のmはありえないのでl = mとする
    else:
        l = m
print(r)

Submission status: Wrong Answer

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

l = -1
r = A[-1] * F[-1] + 1


def ok(c):
    s = 0
    for a, f in zip(A, F):
        s += max(0, a - c//f)
    return s <= K


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

print(r)

Submission status: Wrong Answer

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

l = -1
r = A[-1] * F[-1]


def ok(c):
    s = 0
    for n in range(N):
        s += max(0, A[n] - c//F[n])
    return s <= K


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

print(r)

Submission status: Wrong Answer

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

A.sort()
F.reverse()

l = -1
r = A[-1] * F[-1]


def ok(c):
    s = 0
    for n in range(N):
        s += max(0, A[n] - c//F[n])
    return s <= K


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

print(r)

Submission status: Wrong Answer

Solution code:

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
w=[0,0]
ans=0
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=80
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<ws/f[i]-a[i]:
            w[0]=ws
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws/f[i]
    if p>0:
        w[1]=ws
    else:
        w[0]=ws
print(w[0])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
w=[0,0]
ans=0
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=80
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<ws/f[i]-a[i]:
            w[0]=ws
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws/f[i]
    if p>0:
        w[1]=ws
    else:
        w[0]=ws
print(w[1])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
w=[0,0]
ans=0
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=44
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<ws/f[i]-a[i]:
            w[0]=ws
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws/f[i]
    if p>0:
        w[1]=ws
    else:
        w[0]=ws
print(w[1])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
w=[0,0]
ans=0
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=25
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<ws/f[i]-a[i]:
            w[0]=ws
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws/f[i]
    if p>0:
        w[1]=ws
    else:
        w[0]=ws
print(w[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()))

F.sort(reverse = True)
Amax = max(A)
Fmax = F[0]
As = sum(A)

x=0
if As < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if As-sum(max(xm//f ,0) for f in F) > K: 
            xl = xm + 1
        else: 
            xh = xm
    else:
        x = xl
print(x)

Submission status: Wrong Answer

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

F.sort(reverse = True)
Amax = max(A)
Fmax = F[0]
As = sum(A)

x=0
if As < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    Asum2 = 0
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        if max(As-sum(xm//f for f in F),0 )> K:
            xl = xm + 1
        else:
            xh = xm
    else:
        x = xl
print(x)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])]
m,M,i=0,2**40,1
exec("i,M,m=((i+m)//2,i,m) if sum(-min(0,i-c)/b for b, c in X)<=K else((i+M)//2,M,i);"*50)
print(M)

Submission status: Wrong Answer

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

F.sort(reverse = True)
Amax = max(A)
Fmax = F[0]
As = sum(A)

x=0
if As < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    Asum2 = 0
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        Asum2 = sum(max(0,xm//f) for f in F)
        if As-Asum2 > K: #xm < xmin
            xl = xm + 1
        elif As-Asum2 <= K: #xm >= xmin
            xh = xm
    else:
        x = xl
print(x)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])]
m,M,i=0,2**40,1
exec("i,M,m=((i+m)//2,i,m) if sum(-min(0,i-c)/b for b, c in X)<=K else((i+M)//2,M,i);"*41)
print(M)

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)
#Amax = A[-1]
Amax = max(A)
Fmax = F[0]
#As = sum(a for a in A)
As = sum(A)

x=0
if As < K:
    x = 0
else:
    xl = 0
    xh = Amax*Fmax
    Asum2 = 0
    while xh-xl > 0:
        xm = int((xl+xh)//2)
        Asum2 = sum(xm//f for f in F)
        if As-Asum2 > K:
            xl = xm + 1
        elif As-Asum2 <= K:
            xh = xm
    else:
        x = xl
print(x)

Submission status: Wrong Answer

Solution code:
import math
N,K=map(int,input().split())
X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])]
m,M,i=0,10**12,1
exec("i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);print(m,M);"*50)
print(M)

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    N,K = map(int, input().split())
    A = np.array(input().split(), np.int64)
    F = np.array(input().split(), np.int64)

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

    A.sort()
    F.sort()
    A = A[::-1]
    
    cost = A * F
    down = -1
    up = np.max(cost)
    while up > down + 1:
        mid = (down + up) // 2
        if np.sum(np.where(cost > mid, np.ceil((cost - mid) / F), 0)) <= K:
            up = mid
        else:
            down = mid
    
    print(mid)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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