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())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a = sorted(a)
f = sorted(f,reverse = True)

# =============================================================================
# hq = []
# 
# def is_ok(checking):
#     cost = 0
#     for i in range(n):
#         cost += max(0,math.ceil((a[i]*f[i]-checking)/f[i]))
#     if cost <= k:
#         return True
#     else:
#         return False
# 
# def meguru_bisect(ng, ok):
#     while (abs(ok-ng)>1):
#         mid = (ok+ng)//2
#         if is_ok(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok
# 
# ok = meguru_bisect(-1, 1e+100) 
# =============================================================================
print(int(1))
# 初期値の範囲は取りえる値-1～+1とする←範囲内はok,ngどちらもあり得るため

Submission status: Wrong Answer

Solution code:
import numpy as np
def bin_search(left, right, check):
    while left + 1 < right:
        middle = (left + right) >> 1
        if check(middle):
            right = middle
        else:
            left = middle
    return right

def check(m):
    return np.maximum(A - m // F, Z).sum() <= K

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)
F = np.array(input().split(), dtype=np.int32)
Z = np.zeros((N,), dtype=np.int32)
A.sort()
F = F[np.argsort(-F)]

print(bin_search(0, 10 ** 12, check))

Submission status: Wrong Answer

Solution code:
def isok(arg):
    if arg < 0:
        return False
    count = 0
    for i in range(n):
        count += -(-(a[i]*f[i]-arg)//f[i])
    if count <= k:
        return True
    else:
        return False

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

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(bisect(-1,10**12))

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)

max_a = max(A)
max_f = max(F)

left = 0
right = max_a * max_f

while left <= right:
    x = (left + right) // 2

    sum_ = 0
    for i in range(N):
        if A[i] * F[i] > x:
            sum_ += (A[i] - int(x / F[i]))

    if sum_ == K:
        print(x)
        exit()

    if sum_ > K:
        left = x + 1

    if sum_ < K:
        right = x - 1


print(left)

Submission status: Wrong Answer

Solution code:
import sys
N,K=map(int,input().split())
alist=list(map(int,input().split()))
flist=list(map(int,input().split()))
alist.sort()
flist.sort(reverse=True)
#print(alist)
#print(flist)

def check(m):
  cnt=0
  for i in range(N):
    if alist[i]*flist[i]>m:
      cnt+=-(-(alist[i]*flist[i]-m)//flist[i])
  
  #print(m,cnt,K)
  if cnt<=K:
    return True
  else:
    return False

if sum(alist)<=K:
  print(0)
  sys.exit(0)

baseline=0
for i in range(N):
  baseline=max(baseline,alist[i]*flist[i])
#print(baseline)

l,r=0,baseline
while l<=r:
  mid=(l+r)//2
  #print(l,mid,r)
  if not check(mid-1) and check(mid):
    print(mid)
    break
  elif not check(mid):
    r=mid-1
  else:
    l=mid+1

Submission status: Wrong Answer

Solution code:
import numpy as np

n,k=map(int,input().split())

a=np.array(input().split(),dtype=np.int64)
f=np.array(input().split(),dtype=np.int64)
a.sort()
f.sort()
f=f[::-1]
af=a*f

# r以下にするのに必要修行回数がk以内かどうか
def safe(r):
    return sum(np.maximum(0,af-r+f-1)//f)<=k
    
m=-1
M=10**12

while True:
    pos=(m+M)//2
    print(pos,safe(pos))
    if safe(pos):
        M=pos
    else:
        if m==pos:#終わり
            print(M)
            break
        m=pos

Submission status: Wrong Answer

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

for train in range(k):
    a.sort()
    f.sort()
    af = []
    '''
    print('a = {}'.format(a))
    print('f = {}'.format(f))
    '''
    for i in range(n):
        af.append(a[n-i-1]*f[i])

    maxindex = af.index(max(af))
    if a[n-maxindex-1] >= 1:
        a[n-maxindex-1] -= 1

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    f = list(map(int, input().split()))
    a = sorted(a)
    f = sorted(f)
    f = f[::-1]
    mi = -1  # Impossible
    ma = 10 ** 12  # Possible
    for i in range(100):
        md = mi + (ma - mi) // 2
        if can_achieve(md, a, f, k, n):
            ma = md
        else:
            mi = md
        if ma - mi <= 1:
            break
    print(ma)

def can_achieve(score, a, f, k, n):
    sumb = 0
    for i in range(n):
        b = a[i] - score // f[i]
        sumb += b
    return k >= sumb


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#ABC144-E Gluttony
"""
消化コストの小さい人から食べにくさの大きいものを割り当てるのは確定。
問題は全員のコスト*食べにくさ　の合計ではなく、最もその値が大きい人の
スコアを最小化することである。

最大値の最小化は、最大値を決め打って二分探索。
コストの昇順と食べにくさの降順を対応させ、食べにくさ*need<=決め打った最大値
となるようなneedを求め、k -= max(0,-need+コスト)していく。
kが0未満になってしまった場合はその決め打った最大値は達成できない。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,k = map(int,readline().split())
lsta = list(map(int,readline().split()))
lstf = list(map(int,readline().split()))

lsta.sort()
lstf.sort(reverse=True)

def func(mid,k):
    for i in range(n):
        need = mid//lstf[i] #need以下にしないといけない
        k -= max(0,lsta[i]-need)
        if k < 0:
            return 0
    return 1

def binary_search(): #2分探索
    ok = 10**9
    ng = -1
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if func(mid,k):
            ok = mid
        else:
            ng = mid

    return ok

print(binary_search())

Submission status: Wrong Answer

Solution code:
#ABC144-E Gluttony
"""
消化コストの小さい人から食べにくさの大きいものを割り当てるのは確定。
問題は全員のコスト*食べにくさ　の合計ではなく、最もその値が大きい人の
スコアを最小化することである。

最大値の最小化は、最大値を決め打って二分探索。
コストの昇順と食べにくさの降順を対応させ、食べにくさ*need<=決め打った最大値
となるようなneedを求め、k -= max(0,-need+コスト)していく。
kが0未満になってしまった場合はその決め打った最大値は達成できない。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,k = map(int,readline().split())
lsta = list(map(int,readline().split()))
lstf = list(map(int,readline().split()))

lsta.sort()
lstf.sort(reverse=True)

def func(mid,k):
    for i in range(n):
        if lstf[i] > mid: #コストを0に落とし込まないと達成できない
            need = 0
        else:
            need = mid//lstf[i] #need以下にしないといけない
        k -= max(0,-need+lsta[i])
        if k < 0:
            return 0
    return 1

def binary_search(): #2分探索
    ok = 10**9
    ng = -1
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if func(mid,k):
            ok = mid
        else:
            ng = mid

    return ok

print(binary_search())

Submission status: Wrong Answer

Solution code:
# わからんだろこれ 降順ソート*昇順ソートからの発想が浮かばず
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = 0, 10**20  # 上限わからんから雑

while r - l > 1:
    mid = (r + l) // 2  # 最大値これをめざす
    cur = 0
    for i in range(n):
        # if a[i] * b[i] <= mid:
        #     # Kを使う必要がない
        #     pass
        # else:
        #     # Kからどんくらい使うか これむずくない？
        #     cur += a[i] - mid // b[i]
        # if cur > k:
        #     l = mid
        #     break
        cur += max(0, a[i] - mid // b[i])
        if cur > k:
            break
    if cur > k:
        l = mid
    else:
        r = mid
print(r)

Submission status: Wrong Answer

Solution code:
# わからんだろこれ 降順ソート*昇順ソートからの発想が浮かばず
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = 0, 10**20  # 上限わからんから雑

while r - l > 1:
    mid = (r + l) // 2  # 最大値これをめざす
    cur = 0
    for i in range(n):
        if a[i] * b[i] <= mid:
            # Kを使う必要がない
            pass
        else:
            # Kからどんくらい使うか これむずくない？
            cur += a[i] - mid // b[i]
        if cur > k:
            l = mid
            break
    if cur <= k:
        r = mid
print(r)

Submission status: Wrong Answer

Solution code:
# わからんだろこれ 降順ソート*昇順ソートからの発想が浮かばず
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = 0, 10**20  # 上限わからんから雑

while r - l > 1:
    mid = (r + l) // 2  # 最大値これをめざす
    cur = 0
    for i in range(n):
        if a[i] * b[i] <= mid:
            # Kを使う必要がない
            pass
        else:
            # Kからどんくらい使うか これむずくない？
            cur += a[i] - mid // b[i]
    if cur > k:
        # 使いすぎなので増やす
        l = mid
    else:
        # まだ使えるので減らす
        r = mid
print(r)

Submission status: Wrong Answer

Solution code:
# わからんだろこれ 降順ソート*昇順ソートからの発想が浮かばず
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = 0, 10**20  # 上限わからんから雑

while r - l > 1:
    mid = (r + l) // 2  # 最大値これをめざす
    cur = 0
    for i in range(n):
        if a[i] * b[i] <= mid:
            # Kを使う必要がない
            pass
        else:
            # Kからどんくらい使うか これむずくない？
            cur += a[i] - mid // b[i]
    if cur > k:
        # 使いすぎなので増やす
        l = mid + 1
    else:
        # まだ使えるので減らす
        r = mid
print(r)

Submission status: Wrong Answer

Solution code:
# 効率よくゼロになる数を最大化するのがよさそう
# そんで残ったやつを大きい順にBの小さい方に充てる
# サンプル1は(1, 4)をゼロにするのと(1, 2)をゼロにして残った2を4から引くのとおなじになるので
# ふつうに昇順ソートした小さい方から充てていく

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
start_idx = 0
for i in range(n):
    if k - a[i] >= 0:
        k -= a[i]
        a[i] = 0
    else:
        a[i] -= k
        start_idx = i
        break
ans = 10**10
for i in range(start_idx, n):
    ans = min(ans, a[i] * b[i])
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)

hi = 10**18
lo = -1

while hi - lo > 1:
    mid = (hi + lo) // 2
    tr = 0
    for i in range(N):
        tr += A[i] - mid // F[i]
    if tr > K:
        lo = mid
    else:
        hi = mid

print(hi)

Submission status: Wrong Answer

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

def main():
    n, k=map(int, input().split())
    a=np.array(list(map(int, input().split())), dtype=np.int64)
    f=np.array(list(map(int, input().split())), dtype=np.int64)
    np.sort(a)
    np.sort(f)[::-1]
    l,r=0,10**12
    while l<=r:
        m=(l+r)//2
        tr=np.clip(a-m//f,0,None).sum()
        if tr>k:
            l=m+1
        else:
            r=m-1
    print(l)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

lim = sum(a) -k
if(lim <= 0):
    print(0)
    exit()

min_ = 0
max_ = 10**12+1

for i in range(50):
    tmp = (max_ + min_)//2
    tmp_sum = 0
    for j in range(n):
        tmp_sum += tmp//f[j]

    if(tmp_sum >= lim):
        max_ = tmp
    else:
        min_ = tmp

    if(max_ - min_ == 1):
        break

print(max_)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索、浮き沈みの沈みに注意
N, K = lr()
A = np.array(lr()); A.sort()
F = np.array(lr()); F.sort()
F = F[::-1]
print(A)
print(F)
def check(x):
    limit = x // F # このラインまでにAを落とす
    Y = A - limit
    if np.any(Y > K):
        return False
    cost = Y[Y>=0].sum()
    if cost <= K:
        return True
    else:
        return False

ok = 10 ** 15; ng = -1
while abs(ng-ok) > 1:
    mid = (ok+ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import sys
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
h,l=max(a[i]*f[i] for i in range(n))+1,0

if sum(a)<=k: print(0);sys.exit()

while h-l>1:
    m=(h+l)//2
    practice=sum(max(0,a[i]-m//f[i]) for i in range(n))
    if practice==k: h=m;break
    elif practice<k: h=m
    else: l=m
print(h)

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)
res = 0
for i in range(n):
    if k==0:
        res += A[i]*F[i]
    elif A[i]<=k:
        k -= A[i]
    else:
        A[i] -= k
        k = 0
        res += A[i]*F[i]
print(res)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
t = sum(A)
ok = 10**18
ng = -1
mid = (ok+ng)//2
if t <= k:
    print(0)
else:
    while abs(ok-ng) > 1:
        cur = t
        mid = (ok+ng)//2
        for i in range(n):
            cur -= mid/F[i]
        if cur <= k:
            ok = mid
        else:
            ng = mid
    print(ok)

Submission status: Wrong Answer

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

asum = a.sum()

l,r = 0, 10**13
while l != r:
    mid = (l+r)//2

    can = (asum - np.minimum(mid//f, a).sum()) <= k

    if can:
        r = mid -1
    else:
        l = mid 

print(l)

Submission status: Wrong Answer

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

asum = a.sum()

l,r = 0, 10**13
while l+1 < r:
    mid = (l+r)//2

    can = (asum - np.minimum(mid//f, a).sum()) <= k

    if can:
        r = mid
    else:
        l = mid +1

print(l)

Submission status: Wrong Answer

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

def main():
    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))

    Asum = a.sum()

    l, r = -1, int(1e13)
    while l != r:
        p = (l + r) // 2
        tmp = Asum - np.minimum(a, p//f).sum() <= K
        # print(p, tmp)
        if tmp:
            r = p
        else:
            l = p + 1
    
    print(l)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
#一時保存
def count(target):
    num=0
    for i in range(N):
        temp=target//F[i]
        num+=A[i]-temp
    return num

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**16+1
ng=0

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


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

print(ok)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
#一時保存
def count(target):
    num=0
    for i in range(N):
        temp=target//F[i]
        num+=A[i]-temp
    return num

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**7
ng=0

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


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

print(ok)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
#一時保存
def count(target):
    num=0
    for i in range(N):
        temp=target//F[i]
        num+=A[i]-temp
    return num

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**19
ng=0

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


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

print(ok)

Submission status: Wrong Answer

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

l, r = -1, 200000
while r - l > 1:
    x = (r + l) // 2
    
    res = 0
    for i in range(n):
        res += max(0, a[i] - x // f[i])
    
    if res > k:
        l = x
    else:
        r = x
print(r)

Submission status: Wrong Answer

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

l, r = -1, 200001
while r - l > 1:
    x = (r + l) // 2
    
    res = 0
    for i in range(n):
        res += a[i] - x // f[i]
    
    if res > k:
        l = x
    else:
        r = x
print(r)

Submission status: Wrong Answer

Solution code:
import heapq

n, k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
Minus_A = [-x for x in A]
F = sorted(F, reverse=True)

Sec = []
for i in range(n):
    Sec.append(Minus_A[i]*F[i])

hq = []
for i in range(n):
    heapq.heappush(hq, [Sec[i], Minus_A[i], F[i]])

minus_count = int(k//n)

for i in range(n):
    dec_obj = heapq.heappop(hq)
    if dec_obj[1] < 0:
        dec_obj[1] = min(dec_obj[1] + minus_count, 0)
        dec_obj[0] = dec_obj[1] * dec_obj[2]
        heapq.heappush(hq, dec_obj)
        # print(hq)
    else:
        break

for i in range(k%n):
    dec_obj = heapq.heappop(hq)
    if dec_obj[1] < 0:
        dec_obj[1] = dec_obj[1] + 1
        dec_obj[0] = dec_obj[1] * dec_obj[2]
        heapq.heappush(hq, dec_obj)
        # print(hq)
    else:
        break

ans_obj = heapq.heappop(hq)
ans = ans_obj[0] * -1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

def solve(X):
    s = 0
    for i in range(N):
        if A[i]*F[i]>X:
            s += math.ceil((A[i]*F[i]-X)/F[i])
    # print(X, s)
    return s <= K

if sum(A) <= K:
    print(0)
else:
    l, r = 0, 16
    while l+1<r:
        mid = (l+r)//2
        if solve(mid):
            r = mid
        else:
            l = mid
    print(r)

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 solve(time):
    cnt=0
    for i in range(n):
        tmp = time // f[i]
        if a[i] - tmp > 0:
            cnt += (a[i]-tmp)
    if cnt <= k:
        return True
    else:
        return False

r=0
l=0
for i in range(n):
    r=max(r,a[i]*f[i])

while r-l>1:
    mid=(l+r)//2

    if solve(mid):
        r=mid
    else:
        l=mid
print(r)

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())))
A.sort()
F.sort()
A = A[::-1]
left = 0
right = np.max(A * F)
judge = (left + right) // 2
for _ in range(50):
    rec = judge // F
    recK = np.sum(np.maximum(np.zeros(N), A - rec))
    if recK <= K:
        right = judge
    else:
        left = judge + 1
    if left == right:
        print(left)
        break

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(reverse=True)
F.sort()
left=0
right=10**12
while right-left>1:
    center=(left+right)//2
    temp=0
    flag=0
    for i in range(n):
        a=center//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        left=center
    else:
        right=center
temp=0
for i in range(n):
    a=center//F[i]
    if a>A[i]:
        continue
    else:
        temp+=A[i]-a
if temp<=k:
    ans=left
else:
    ans=right
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(reverse=True)
F.sort()
left=0
right=10**12
while right-left>1:
    center=(left+right)//2
    temp=0
    flag=0
    for i in range(n):
        a=center//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        left=center
    else:
        right=center
print(right)

Submission status: Wrong Answer

Solution code:
def main():
    import numpy as np
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    A.sort()
    F.sort(reverse=True)
    A=np.array(A)
    F=np.array(F)

    def ok(x): #チームの成績をxとするような修行の仕方が存在するか
        Fx=x//F
        return sum(A-Fx)<=k
    
    l=-1
    r=10**18
    while r-l>1:
        mid=(r+l)//2
        if ok(mid):
            r=mid
        else:
            l=mid
    print(r)   

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

def ok(x):
    tot = 0
    for i in range(n):
        tot += x//F[i]
    if sum(A) - k <= tot:
        return True
    else:
        return False

l = -1
r = 10**18
while l+1 < r:
    c = (l+r)//2
    if ok(c):
        r = c
    else:
        l = c
print(r)

Submission status: Wrong Answer

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

    l_score=-1
    r_score=10**12
    while l_score<r_score-1:
        t_score=(l_score+r_score)//2
        count=0
        for i in range(N):
            count+=A[i]-t_score//F[i]
        if count<=K:
            r_score=t_score
        else:
            l_score=t_score
    print(r_score)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil

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) # 食べにくさ
# K: 修行の回数

cost = [a*f for a,f in zip(A,F)]

# にぶたん
# K回以下の修行でチーム成績がMになるか
# Mを固定して考える
def grade_is(M:int):
    training = 0
    for i in range(N):
        if cost[i] > M:
            training += (cost[i] - M) / F[i]
    return training <= K

ok = 10 ** 18 + 1
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if grade_is(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
#一時保存
def count(target):
    num=0
    for i in range(N):
        num+=max(-(-(F[i]-target))//A[i],0)
    return num

N,K=map(int,input().split())

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

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

for i in range(N):
    F[i]*=A[i]

high=max(F)+1
low=0

while True:
    print(high,low)
    if (high-low)==1:
        print(high,low)
        exit()
    mid=(high+low)//2
    temp=count(mid)
    if temp==K:
        print("A")
        print(mid)
        exit()
    elif temp>K:
        low=mid
    else:
        high=mid

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 det(x):
    KK = K
    for i in range(N):
        if int(max(0,A[i]-x/F[i])) == max(0,A[i]-x/F[i]):
            KK -= int(max(0,A[i]-x/F[i]))
        else:
            KK -= int(max(0,A[i]-x/F[i])) + 1
        if KK < 0:
            return False
        #print(KK)
    return True

if det(0):
    print(0)
else:
    R = [0,10**6]

    while R[1] - R[0] > 1:
        if det(int((R[0]+R[1])//2)):
            R[1] = int((R[0]+R[1])//2)
        else:
            R[0] = int((R[0]+R[1])//2)
        #print(R)

    print(R[1])#R[0]はFalse, R[1]はTrueが基本

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 det(x):
    KK = K
    for i in range(N):
        if max(0,int(A[i]-x/F[i])) == max(0,A[i]-x/F[i]):
            KK -= max(0,int(A[i]-x/F[i]))
        else:
            KK -= max(0,int(A[i]-x/F[i])) + 1
        if KK < 0:
            return False
        #print(KK)
    return True

if det(0):
    print(0)
else:
    R = [0,10**6]

    while R[1] - R[0] > 1:
        if det(int((R[0]+R[1])//2)):
            R[1] = int((R[0]+R[1])//2)
        else:
            R[0] = int((R[0]+R[1])//2)
        #print(R)

    print(R[1])#R[0]はFalse, R[1]はTrueが基本

Submission status: Wrong Answer

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

bh = 10**6
bl = 0
m = 10**3
while True:
    t = K
    for i in range(len(A)):
        if A[i]*F[i] > m:
            t -= A[i] - int(m / F[i])
            if t < 0:
                break
    if t >= 0:
        bh = m
        m = (bh + bl) // 2
    else:
        bl = m + 1
        m = (bh + bl) // 2
    if bh == bl:
        print(bh)
        exit(0)

Submission status: Wrong Answer

Solution code:
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)
if sum(A)<=K:
    print(0)
    exit()
low=0
high=10**6+10
while(high-low>1):
    mid=(low+high)//2
    x=0
    for i in range(N):
        x+=max(A[i]-(mid//F[i]),0)
        #A[i]-mid//F[i]<=t
    #上限をmid以下としたとき
    #low:修行回数がKより多くなってしまうのでだめ
    #high:修行回数がK以下なのでOK
    if x<=K:
        high=mid
    else:
        low=mid
print(high)

Submission status: Wrong Answer

Solution code:
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)
if sum(A)<=K:
    print(0)
    exit()
low=0
high=10**6
while(high-low>1):
    mid=(low+high)//2
    x=0
    for i in range(N):
        t=max(A[i]-(mid//F[i]),0)
        x+=t
        A[i]-mid//F[i]<=t
    #上限をmid以下としたとき
    #low:修行回数がKより多くなってしまうのでだめ
    #high:修行回数がK以下なのでOK
    if x<=K:
        high=mid
    else:
        low=mid
print(high)

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())), reverse=True)

lo = 0
hi = sum(ai * fi for ai, fi in zip(a, f))
mid = (hi + lo) // 2
ans = hi

for i in range(hi):
  cost = sum(max(0, ai - math.floor(mid / fi)) for ai, fi in zip(a,f))
  if k >= cost:
    hi = mid
    ans = mid
  else:
    lo = mid + 1
  if hi == lo:
    break;
  mid = (hi + lo + 1) // 2

    
print(ans)

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())), reverse=True)

lo = 0
hi = sum(ai * fi for ai, fi in zip(a, f))
mid = (hi + lo) // 2
ans = hi

for i in range(hi):
  cost = sum(max(0, ai - math.floor(mid / fi)) for ai, fi in zip(a,f))
  if k >= cost:
    hi = mid - 1
    ans = mid
  else:
    lo = mid + 1
  if hi == lo:
    break;
  mid = (hi + lo) // 2

    
print(ans)