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 heapq

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

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

heapq.heapify(AF)
for i in range(max(N, K)):
    mul, val = heapq.heappop(AF)
    val = -val
    if val:
        temp = mul // val
        val -= 1
        heapq.heappush(AF, (temp * val, -val))


print(-AF[0][0])

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)

for i in range(n):
    if k==0:
        break
    else:
        if a[i]<k:
            k-=a[i]
            a[i]=0
        else:
            a[i]-=k
            k=0
ans=sum([i*j for i,j in zip(a,f)])
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
AS = list(map(int, input().split()))
FS = list(map(int, input().split()))
AS = sorted(AS)
FS = sorted(FS, reverse=True)

import math

perm = sorted(list(range(N)), key=lambda i:AS[i] * FS[i], reverse=True)

onLeft = 1
costToShift = 1/FS[perm[0]]

for index, nextIndex in zip(perm, perm[1:]):
    
    curCost = AS[index] * FS[index]
    nextCost = AS[nextIndex] * FS[nextIndex]

    # Try to get all cost to nextCost
    tryCost = costToShift * (curCost - nextCost)

    if K >= tryCost:
        K -= tryCost
    else:
        print(int(curCost - K // math.ceil(costToShift) + 0.5))
        quit()

    onLeft += 1
    costToShift += 1/FS[nextIndex]

curCost = AS[perm[-1]] * FS[perm[-1]]

print(max(0, int(curCost - K // math.ceil(costToShift) + 0.5)))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

invb=[1/i for i in b]

print(max( int( 1/sum(invb)*(sum(a)-k)+1),0 ) )

Submission status: Wrong Answer

Solution code:
import sys
import bisect
input = sys.stdin.readline
def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    f = list(map(int,input().split()))
    if sum(a)<=k:
        print(0)
    else:
        a.sort()
        f.sort(reverse=True)
        mul=[]
        for i in range(n):
            mul.append([a[i]*f[i],a[i]])
        mul.sort(reverse=True)
        top=0
        for _ in range(k):
            mul[top][0]-=(mul[top][0]//mul[top][1])
            mul[top][1]-=1
            index=1
            if mul[top][0]<mul[top+1][0]:
                mul.append([0,0])
            while mul[top][0]<mul[top+1][0] and mul[top][0]>=mul[-1-index][0]:
                mul[-index]=mul[-1-index]
                index+=1
            if mul[top][0]<mul[top+1][0]:
                mul[-index]=mul[top]
                mul[top]=[0,0]
                top+=1
        print(mul[top][0])

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort(reverse=True)
#print(a)
#print(b)
big = 44
stand = 2 ** big - 1
width = 2 ** (big-1)
while True:
  tmp = []
  for i in range(n):
    tmp.append(max(0,a[i]-stand//b[i]))
  if sum(tmp) <= k:
    stand -= width
    width //= 2
  else:
    stand += width
    width //= 2
  #print(stand,tmp)
  if width == 0:
    if sum(tmp) <= k:
      print(stand)
    else:
      print(stand+1)
    break

Submission status: Wrong Answer

Solution code:
abc_1 = input()
abc_2 = input()
abc_3 = input()
nk = []
for c1 in abc_1.split(' '):
    nk.append(int(c1))
appeti = []
for c2 in abc_2.split(' '):
    appeti.append(int(c2))
food = []
for c3 in abc_2.split(' '):
    food.append(int(c3))
appeti.sort()
food.sort(reverse=True)
chk = 0
sum = 0
for c4 in appeti:
    if c4 < nk[1]:
        appeti[chk] = 0
        chk = chk+1
        nk[1] = nk[1]-c4
if chk == nk[0]:
    print(0)
else:
    appeti[chk] = appeti[chk]-nk[1]
for c5 in range(nk[0]):
    sum = sum + appeti[c5]*food[c5]
print(sum)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
K = list(map(int, input().split()))
C = list(map(int, input().split()))
K = sorted(K, reverse = True)
C = sorted(C, reverse = False)

K.append(0)
prev = max(K)
m = 0
for i, k in enumerate(K):
  if prev == k:
    continue
  m += (prev - k) * i
  if m > M:
    m -= M
    break
  prev = k
if prev == 0:
  print(0)
elif (i-1-m) < 0:
  print(prev * C[0])
else:
  print(prev * C[i - 1 - m])

Submission status: Wrong Answer

Solution code:
from math import*
n,k=map(int,input().split())
*a,=map(int,input().split())
*f,=map(int,input().split())
ref=sorted([(x*y,y) for x,y in zip(sorted(a),sorted(f)[::-1])])[::-1]
l=0
r=10**12
while r-l>1:
	m=(l+r)//2
	rest=k
	flg=1
	for z,y in ref:
		if m>=z:
			break
		if rest>=ceil((z-m)/y):
			rest-=ceil((z-m)/y)
		else:
			flg=0
	if flg:
		r=m
		if r-l==1:
			r=l
	else:
		l=m
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()))

import copy
A.sort(reverse = True)
DA = copy.copy(A)
F.sort()

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

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

def judge(val):
    cnt = 0
    for i in range(N):
        if (values[i] > val):
            cnt += A[i]-val//F[i]
    
    return cnt<=K

s = 0
e = max(A)+10
while (s<e):
    c = (s+e)//2
    if judge(c):
        e = c-1
        
    else:
        s = c+1

while(judge(c)):
    c-=1
print(c+1)

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()]
s = sum(a)
l, r = 0, 10 ** 18 + 1

a.sort()
f.sort()

while l <= r:
    m = (l + r) // 2
    summ = 0

    for x in range(n):
        summ += m // f[x]

    summ = s - summ

    if summ > k:
        l = m + 1
    else:
        r = m - 1

print(l)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort(reverse=True)
#print(a)
#print(b)
big = 10
stand = 2 ** big - 1
width = 2 ** (big-1)
while True:
  tmp = []
  for i in range(n):
    tmp.append(max(0,a[i]-stand//b[i]))
  if sum(tmp) <= k:
    stand -= width
    width //= 2
  else:
    stand += width
    width //= 2
  #print(stand,tmp)
  if width == 0:
    if sum(tmp) <= k:
      print(stand)
    else:
      print(stand+1)
    break

Submission status: Wrong Answer

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


def train(L, t):
    for i in range(len(L)):
        if L[i] <= t:
            t -= L[i]
            L[i] = 0
        if t == 0:
            break
    return L, t


A, k = train(A, k)
A = sorted(A)
if k != 0:
    A[-1] = max(0, A[-1]-k)
    A = sorted(A)

ans = 0
for a, f in zip(A, F):
    ans += a*f

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

N, K = map(int, input().split())
#A_lis = list(map(int, input().split()))
A_lis = list(map(lambda x: int(x)*(-1), input().split()))
F_lis = list(map(int, input().split()))

heapq.heapify(A_lis)
heapq.heapify(F_lis)

for i in range(K):
    maxA = heapq.heappop(A_lis)
    heapq.heappush(A_lis, maxA+1)

ans = 0
for i in range(N):
    ans_try = (-1)*heapq.heappop(A_lis)*heapq.heappop(F_lis)
    if ans<ans_try:
        ans = ans_try
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()
a = a[::-1]
kaketa = []
for i in range(n):
    kaketa.append(a[i]*f[i])

left = 0
right = max(kaketa)

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

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

Submission status: Wrong Answer

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

t = (10**12) / 2
q = set()
ans=(10**12) / 2
h = t
while t not in q:
  h = 1 + h//2
  q.add(t)
  l = k
  ans0=0
  for i,j in zip(a,b):
    l -= max(i-int(t / j),0)
    if l < 0:
      t += h
      break
  else:
    ans=min(ans,t)
    t -= h
print(int(ans))

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)

i=0
while i<n and k>0:
    tmp = min(a[i],k)
    a[i] -= tmp
    i+=1
    k-=tmp

sum=0
for i in range(0,n):
    sum += a[i]*f[i]
print(sum)

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

for i in range(len(A)):
  if K>0:
    if A[i]-K<0:
      K=K-A[i]
      A[i]=0
    else:
      A[i]=A[i]-K
      K=K-A[i]
      
A=sorted(A,reverse=True)
print(max([x * y for (x, y) in zip(A, F)]))

Submission status: Wrong Answer

Solution code:
import heapq
import numpy

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


def solve(member, max_try, A, F):
    AA = [[-x, x] for x in A]

    heapq.heapify(AA)

    for i in range(K):
        x, y = heapq.heappop(AA)
        heapq.heappush(AA, [-(y - 1), y - 1])

    AAA = [x[1] for x in AA]

    sorted_F = numpy.array(sorted(F, reverse=1))
    sorted_AAA = numpy.array(sorted(AAA))

    return max(sorted_F * sorted_AAA)


print(solve(N, K, A, F))

Submission status: Wrong Answer

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

  rest = sum(A) - K
  if rest <= 0: return 0

  _max = max(F)
  _min = min(F)
  base = (_max // _min) * _min
  r = sum([base // f for f in F])
  cost = base // r

  while True:
    _sum = sum([cost // f for f in F])
    if _sum >= rest: return cost
    cost += _min

print(solve())

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)
m=0
for i in range(n):
    m=max(m,a[i]*f[i])
x=m//2
l=0
r=m
def check(x):
    p=0
    for i in range(n):
        if x//f[i]<a[i]:
            p+=a[i]-x//f[i]
    if p>k:
        return False
    else:
        return True
while 1<r-l:
    if check(x):
        r=x
        x=(r-l)//2
    else:
        l=x
        x=(r-l)//2
print(r)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = list( map(int, input().split()) )
f = list( map(int, input().split()) )
a.sort()
f.sort(reverse=True)
i = 0
while k > 1:
    tmp = min(a[i], k)
    a[i] -= tmp
    k -= tmp
    if i==n-1:
        break
    i += 1
pfm = 0
for i in range(n):
    pfm += a[i] * f[i]
print(pfm)

Submission status: Wrong Answer

Solution code:
import heapq
from math import ceil
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()
F = inpl()
S = sum(A)
M = S - K
if M <= 0:
    print(0)
    exit()

A.sort()
F.sort(reverse=True)
Km = K+1
W = [True]*N
while Km > K:
    n = M/sum(1/F[i] for i in range(N) if W[i])
    G = []
    for i in range(N):
        g = int(ceil(n/F[i]))
        if g <= A[i]:
            G.append(g)
        else:
            G.append(A[i])
            W[i] = False
    Km = S - sum(G)
K -= Km
que = [(-G[i]*F[i], i) for i in range(N)]
heapq.heapify(que)
while K > 0:
    p, i = heapq.heappop(que)
    q, j = que[0]
    p, q = -p, -q
    d = p - q
    k = int(ceil(d/F[i]))
    if k == 0:
        k = 1
    if k >= K:
        G[i] -= K
        p -= K*F[i]
        break
    else:
        G[i] -= k
        p -= k*F[i]
        K -= k
        heapq.heappush(que,(-p,i))
p, i = heapq.heappop(que)
print(-p)

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 = np.sort(A)[::-1]
F = np.sort(F)
# 二部探索法　Aの最大値をどこまで減らせるか
if A.sum() <= K:
    print(0)
    exit()
if K == 0:
    print((A * F).max())
up = (A * F).max() # 可能 mid は完食にかかる時間
low = 0 # 不可能
while up > low + 1:
    mid = (up + low) // 2
    if (A - (mid // F)).sum() <= K: #可能
        up = mid
    else:
        low = mid
print(up)

Submission status: Wrong Answer

Solution code:
from numpy import*
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n,k=map(int,input().split())
    a=sorted(map(int,input().split()))
    b=sorted(map(int,input().split()),reverse=1)
    #print(a,b)
    ok=max(a)*max(b)
    ng=0
    
    def check(a,b,mid,k):
        a=array(a)
        b=array(b)
        c=[a[k]-mid//b[k]for k,v in enumerate(a*b)if v>mid]
#        print(c)
        if sum(c)<=k:
            return 1
        else:
            return 0
            
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if check(a,b,mid,k):
            ok=mid
        else:
            ng=mid
    print(ok)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

a1 = sorted(a, reverse=True)
a2 = sorted(a)

f1 = sorted(f, reverse=True)
f2 = sorted(f)

for i in range(n):
  if k >= a1[i]:
    k -= a1[i]
    a1[i] = 0
  else:
    a1[i] -= k
    k = 0
    break
    
for i in range(n):
  if k >= a2[i]:
    k -= a2[i]
    a2[i] = 0
  else:
    a2[i] -= k
    k = 0
    break

a1 = sorted(a1)
a3 = sorted(a1, reverse=True)
a2 = sorted(a2)
a4 = sorted(a2, reverse=True)


c1 = [0]*n
c2 = [0]*n
c3 = [0]*n
c4 = [0]*n
c5 = [0]*n
c6 = [0]*n
c7 = [0]*n
c8 = [0]*n

for j in range(n):
  c1[j] = a1[j]*f1[j]
  c2[j] = a1[j]*f2[j]
  c3[j] = a2[j]*f1[j]
  c4[j] = a2[j]*f2[j]
  
  c5[j] = a3[j]*f1[j]
  c6[j] = a3[j]*f2[j]
  c7[j] = a4[j]*f1[j]
  c8[j] = a4[j]*f2[j]
  
  
#print(max(c1), max(c2), max(c3), max(c4))
print(min(max(c1), max(c2), max(c3), max(c4), max(c5), max(c6), max(c7), max(c8)))

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(reverse=True)
def is_ok(x):
  c=0
  for i in range(n):
    c+=max(A[i]-x//F[i],0)
  if c<=k:
    return True
  else:
    return False
l=min(A[i]*F[i] for i in range(n))
r=max(A[i]*F[i] for i in range(n))
while l!=r:
  m=(l+r)//2
  if is_ok(m):
    r=m
  else:
    l=m+1
print(l)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort(reverse=True)
#print(a)
#print(b)
big = 42
stand = 2 ** big - 1
width = 2 ** (big-1)
while True:
  tmp = []
  for i in range(n):
    tmp.append(max(0,a[i]-stand//b[i]))
  if sum(tmp) <= k:
    stand -= width
    width //= 2
  else:
    stand += width
    width //= 2
  #print(stand,tmp)
  if width == 0:
    if sum(tmp) <= k:
      print(stand)
    else:
      print(stand+1)
    break

Submission status: Wrong Answer

Solution code:
k=list(map(int,input().split()))
A=list(map(int,input().split()))
F=list(map(int,input().split()))
N = int(k[0])
K = int(k[1])
A.sort()
F.sort(reverse=True)
l = [0] * N
w = 0
for i in range(N):
    p = A[i]*F[i]
    l[i] = p
    if(p > w):
        w = p

while(K > 0):
    #t = [i for i, v in enumerate(l) if v == max(l)] 
    for i in [i for i, v in enumerate(l) if v == max(l)] :
        A[i] = A[i]-1
        l[i] = l[i] - F[i]
        K = K - 1
        if(K == 0 | max(l) == 0):
            break
max(l)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a.sort()
f.sort()
a = a[::-1]
a = np.array(a)
f = np.array(f)
kaketa = a * f

left = 0
right = max(kaketa)

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

print(left)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
AS = list(map(int, input().split()))
FS = list(map(int, input().split()))
AS = sorted(AS)
FS = sorted(FS, reverse=True)

perm = sorted(list(range(N)), key=lambda i:AS[i] * FS[i], reverse=True)

onLeft = 1
costToShift = 1/FS[perm[0]]

for index, nextIndex in zip(perm, perm[1:]):
    
    curCost = AS[index] * FS[index]
    nextCost = AS[nextIndex] * FS[nextIndex]

    # Try to get all cost to nextCost
    tryCost = costToShift * (curCost - nextCost)

    if K >= tryCost:
        K -= tryCost
    else:
        print(int(curCost - K // costToShift + 0.5))
        quit()

    onLeft += 1
    costToShift += 1/FS[nextIndex]


curCost = AS[perm[-1]] * FS[perm[-1]]

print(max(0, int(curCost - K // costToShift + 0.5)))

Submission status: Wrong Answer

Solution code:
n,k=[int(_) for _ in input().split()]
a=[int(_) for _ in input().split()]
f=[int(_) for _ in input().split()]
f.sort(reverse=True)
a.sort(reverse=True)
a.append(0)
s=[a[0]]
for i in range(1,n):s.append(s[-1]+a[i])
ans=10**13
for i in range(n):
    p=s[i]-a[i+1]*(i+1)
    if k >= p:
        ng=-1
        ok=n+1
        while ok-ng>1:
            mid=(ok+ng)//2
            if s[-1]-s[mid] <= k-p:
                ok=mid
            else:
                ng=mid
        ans=min(ans,a[i+1]*f[ok])
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()
ok = max(a)*max(f)
ng = -1

while ok-ng > 1:
    mid = (ok+ng)//2
    t = 0
    for i in range(n):
        t += a[i]-int(mid/f[i])
    if t > k:
        ng = mid
    else:
        ok = mid

print(ok)

Submission status: Wrong Answer

Solution code:
input_line= input().split()
mamber=int(input_line[0])
number=int(input_line[1])
member_cost= sorted(map(int,input().split()), reverse=True)
food_cost= sorted(map(int,input().split()), reverse=True)
mem_index=0
max_cost=0
current_cost=0
for mem in member_cost:
    if mem <= number and number!= 0:
        current_cost=(mem-mem)*food_cost[mem_index]
        number-=mem
    elif mem > number and number!= 0:
        current_cost=(mem-number)*food_cost[mem_index]
        number=0
    elif number== 0:
        current_cost=mem*food_cost[mem_index]
    mem_index+=1
    if current_cost>max_cost:
        max_cost=current_cost
print (max_cost)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7




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

    suma = sum(a)

    def ok(v):
        cnt = 0
        sa = 0
        for i in range(n):
            x = v // f[i]
            sa += x
        if suma - k <= sa:
            return True
        else:
            return False





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

    
            
    

    

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
input_line= input().split()
mamber=int(input_line[0])
number=int(input_line[1])
member_cost= sorted(map(int,input().split()), reverse=True)
food_cost= sorted(map(int,input().split()), reverse=True)
mem_index=0
max_cost=0
current_cost=0
print (member_cost)
print (food_cost)
for mem in member_cost:
    if mem <= number and number!= 0:
        current_cost=(mem-mem)*food_cost[mem_index]
        number-=mem
    elif mem > number and number!= 0:
        current_cost=(mem-number)*food_cost[mem_index]
        number=0
    elif number== 0:
        current_cost=mem*food_cost[mem_index]
    mem_index+=1
    if current_cost>max_cost:
        max_cost=current_cost
print (max_cost)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
f = [int(i) for i in input().split()]
ma = 10 ** 12
mi = 0
al = sum(a) - k
mf = max(f)


def isok(x):
    j = al
    for i in f:
        j -= min(x // i, mf)
        if j <= 0:
            return True
    return False


while mi != ma:
    m = (mi + ma) // 2
    if isok(m):
        ma = m
    else:
        mi = m+1
print(mi)

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))

As.sort()
As.reverse()
Fs.sort()
arr = []
M = 0
for a, f in zip(As, Fs):
    af = a*f
    arr.append((af, a, f))
    M = af if af > M else M

f = -1
t = M
while f + 1 < t:
    m = f + math.ceil((t-f) / 2)
    k = K
    for AF, A, F in arr:
        d = A - m // F
        if d > k:
            f = m
            break
        k -= d
    else:
        t = m

print(t)

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 = np.sort(A)[::-1]
F = np.sort(F)
# 二部探索法　Aの最大値をどこまで減らせるか
if A.sum() <= K:
    print(0)
    exit()
up = (A * F).max() # 可能 mid は完食にかかる時間
low = 0 # 不可能
while up > low + 1:
    mid = (up + low) // 2
    if (A - (mid // F)).sum() <= K: #可能
        up = mid
    else:
        low = mid
print(up)

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 = max(a)*max(f)
ng = -1

while ok-ng > 1:
    mid = (ok+ng)//2
    t = 0
    for i in range(n):
        t += a[i]-int(mid/f[i])
    if t > k:
        ng = mid
    else:
        ok = mid

print(ok)

Submission status: Wrong Answer

Solution code:
#A=int(input())
#A=list(map(int,(input().split())))
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)
noruma=10**18 // 2
sabun=10**18 // 4
for x in range(60):
	tasuku=0
	for i in range(N):
		if (A[i]*F[i]>noruma):
			tasuku+=A[i]-(noruma//F[i])
	if tasuku>K:#無理
		noruma+=sabun
		sabun=sabun//2+1
	else:#いけた
		noruma-=sabun
		sabun=sabun//2+1
	if sabun==2:sabun=1
	#print(noruma,sabun)
if tasuku<=K:
	noruma+=1
	#print("modosu",sabun)
print(noruma)

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 = np.sort(A)[::-1]
F = np.sort(F)
# 二部探索法　Aの最大値をどこまで減らせるか
if A.sum() <= K:
    print(0)
    exit()
up = A[0] * F[0] # 可能 mid は完食にかかる時間
low = 0 # 不可能
while up > low + 1:
    mid = (up + low) // 2
    if (A - (mid // F)).sum() <= K: #可能
        up = mid
    else:
        low = mid
print(up)

Submission status: Wrong Answer

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

for _ in range(15):
    summary = []
    for i,j in zip(A, F):
        summary.append(i*j)
    tgt = summary.index(max(summary))
    A[tgt] -= 1
print(max(summary))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))

As.sort()
As.reverse()
Fs.sort()
arr = []
M = 0
for a, f in zip(As, Fs):
    af = a*f
    arr.append((af, a, f))
    M = af if af > M else M

f = -1
t = M
while f + 1 < t:
    m = f + (t-f) // 2
    k = K
    for AF, A, F in arr:
        d = A - m // F
        if d > k:
            f = m
            break
        k -= d
    else:
        t = m

print(t)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
f = [int(i) for i in input().split()]
ma = 10 ** 12
mi = 1
al = sum(a) - k


def isok(x):
    j = al
    for i in f:
        j -= x // i
        if j <= 0:
            return True
    return False


while mi != ma:
    m = (mi + ma) // 2
    if isok(m):
        ma = m
    else:
        mi = m+1
print(mi)

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)
AF = [[a, f] for a, f in zip(A, F)]

if sum(A)<K:
    print(0)
    quit()

while K>1:
    herasu = min(K//2, N)
    AF.sort(key=lambda x: x[0]*x[1], reverse=True)
    for i in range(herasu):
        AF[i][0] -= 1
    K -= herasu

if K:
    AF.sort(key=lambda x: x[0]*x[1], reverse=True)
    for i in range(herasu):
        AF[i][0] -= 1

print(max(a*f for a, f in 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()))

import math
A = sum(a)
c = A - k

def C(d):
    tmp = 0
    for _f in f:
        tmp += int(d / _f)
    return tmp - c

lb = -1
ub = 10 ** 12 + 1
while (ub - lb) > 1:
    mid = (ub + lb) // 2
    if C(mid) >= 0:
        ub = mid
    else:
        lb = mid
print(ub)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = sorted(LI())
F = sorted(LI(), reverse=True)
ok = A[-1] * F[0]
ng = -1
while ok > ng + 1:
    mid = (ok + ng) // 2
    ret = 0
    for i in range(n):
        if A[i]:
            ret += (A[i] * F[i] - mid) // F[i] + bool((A[i] * F[i] - mid) % F[i])
    if ret > k:
        ng = mid
    else:
        ok = 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()))

import math
A = sum(a)
c = A - k

def C(d):
    tmp = 0
    for _f in f:
        tmp += int(d / _f)
    return tmp - c

lb = -1
ub = 10 ** 12
while (ub - lb) > 1:
    mid = (ub + lb) // 2
    if C(mid) >= 0:
        ub = mid
    else:
        lb = mid
print(ub)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
F = sorted(list(map(int, input().split())), reverse = True)
i = 0
while K > 0 and i < N:
  if A[i] < K:
    K -= A[i]
    A[i] = 0
  else:
    A[i] -= K
    K = 0
  i += 1
A = sorted(A)
print(max([a*f for a, f in zip(A, F)]))

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 = np.sort(A)[::-1]
F = np.sort(F)
# 二部探索法　Aの最大値をどこまで減らせるか
if A.sum() <= K:
    print(0)
    exit()
up = A[0] * F[0] # 可能 mid は完食にかかる時間
low = 0 # 不可能
while up > low + 1:
    mid = (up + low) // 2
    if (A - (mid / F)).sum() <= K: #可能
        up = mid
    else:
        low = mid
print(up)

Submission status: Wrong Answer

Solution code:
import sys
import math

input = sys.stdin.readline

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)

cost = []
for ai, fi in zip(A,F):
	cost.append([ai*fi,fi])
cost.sort(reverse=True)

thmin = -1
thmax = cost[0][0]+1

while thmax-thmin!=1:
	print(thmin,thmax)
	th = (thmin+thmax)//2
	ktmp = 0
	ind = 0
	judge = True
	while True:
		ci, fi = cost[ind]
		if ci<=th: break
		ktmp += math.ceil((ci-th)/fi)
		if ktmp>K:
			judge = False
			break
		ind += 1
		if ind==N: break
	if judge:
		thmax = th
	else:
		thmin = th

print(thmax)

Submission status: Wrong Answer

Solution code:
import copy

n, k1 = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = copy.deepcopy(A)
B = sorted(B)
k2 = copy.deepcopy(k1)
F = sorted(list(map(int, input().split())), reverse=True)

for i in range(n):
    if k1 >= A[i]:
        k1 -= A[i]
        A[i] = 0
    if k1 == 0:
        break

for i in range(n):
    if k2 >= B[i]:
        k2 -= B[i]
        B[i] = 0
    if k2 == 0:
        break

A = sorted(A)
B = sorted(B)

ans1 = 0
ans2 = 0
for a, b, f in zip(A, B, F):
    ans1 += a*f
    ans2 += b*f

print(min(ans1, ans2))