Problem:


Score: 500 points

Problem Statement

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

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

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

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

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

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

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

Constraints

All values in input are integers.

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

0 \leq K \leq 10^{18}

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

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the minimum possible score of the team.

Sample Input 1

3 5
4 2 1
2 3 1

Sample Output 1

2

They can achieve the score of 2, as follows:

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

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

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

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

Sample Input 2

3 8
4 2 1
2 3 1

Sample Output 2

0

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

Sample Input 3

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

Sample Output 3

12



Sample input:
3 5
4 2 1
2 3 1


Sample output:
2

Submission status: Wrong Answer

Solution code:

n, k = map(int, input().split())
l=list(map(int, input().split()))
f=list(map(int, input().split()))
t=[]
ans=int(0)
l.sort()
f.sort()
f.reverse()


for i in range(k):
    t=[]
    l.sort()
    for i in range(n):
        t.append(l[i]*f[i])


l[t.index(max(t))] -=1

ans=max(t)
if ans>=0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

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

A = sorted(A)
F = sorted(F, reverse= True)
S = [(-A[i]*F[i], i) for i in range(N)]


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

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

print(mid)

Submission status: Wrong Answer

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

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

A = sorted(A)
F = sorted(F, reverse= True)
S = [(-A[i]*F[i], i) for i in range(N)]


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

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

print(mid)

Submission status: Wrong Answer

Solution code:


n,k = map(int,input().split())	
p_li = list(map(int,input().split()))
f_li = list(map(int,input().split()))

p_li.sort()

f_li.sort()
f_li.reverse()

p_f=[ p_li[i]*f_li[i] for i in range(n)]
print(p_f)

while(k>0):
    max_index=p_f.index(max(p_f))
    p_li[max_index]-=1
    p_f[max_index]=p_li[max_index]*f_li[max_index]
    print(p_f)
    k-=1

Submission status: Wrong Answer

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

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

A = sorted(A)
F = sorted(F, reverse= True)
S = [(-A[i]*F[i], i) for i in range(N)]


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

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

print(mid)

Submission status: Wrong Answer

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

for index,man in enumerate(a_list):
    if k - man >= 0:
        k = k - man
        a_list[index] = 0
    else:
        a_list[index] = man - k
        break;
a_list = sorted(a_list,reverse=True)
ans = 0
for i in range(n):
    ans = a_list[i]*f_list[i] if ans <= a_list[i]*f_list[i] else ans
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in 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-a[i] > 0):
        k = k-a[i]
        a[i] = 0
    else:
        a[i] = a[i]-k
        break

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

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in 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-a[i] > 0):
        k = k-a[i]
        a[i] = 0
    else:
        a[i] = a[i]-k
        break

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

print(ans)

Submission status: Wrong Answer

Solution code:
#E問題
import numpy as np 
N, K = map(int,input().split())
A = map(int,input().split())
F = map(int,input().split())

A = np.array(sorted(A,reverse=True))
F = np.array(sorted(F,reverse=True))

remain = K
i = 0
while remain > 0 and i < N:
    if remain >= A[i]:
        remain = remain-A[i]
        A[i] = 0
    else:
        A[i] = A[i]-remain
        remain = 0
    i=i+1
print(np.amax(A*F))

Submission status: Wrong Answer

Solution code:
#E問題
import numpy as np 
N, K = map(int,input().split())
A = map(int,input().split())
F = map(int,input().split())

A = np.array(sorted(A,reverse=True))
F = np.array(sorted(F,reverse=True))

remain = K
i = 0
while remain > 0 and i < N:
    if remain >= A[i]:
        remain = remain-A[i]
        A[i] = 0
    else:
        A[i] = A[i]-remain
        remain = 0
    i=i+1
print(A,F)
print(np.amax(A*F))

Submission status: Wrong Answer

Solution code:
import numpy as np
import heapq
def main():
    I=[int(x) for x in input().split()]
    A=[int(x) for x in input().split()]
    F=[int(x) for x in input().split()]
    N=I[0]
    K=I[1]

    A.sort()
    F.sort(reverse=True)
    A=np.array(A)
    F=np.array(F)
    FR=1/F
    FR=FR/np.sum(FR)*(np.sum(A)-K)
    FR=A-FR
    FR*=-1
    FR=FR.tolist()
    FR=[(x[1],x[0],0) for x in enumerate(FR)]
    heapq.heapify(FR)
    for _ in range(K):
        mx=heapq.heappop(FR)
        if mx[0]>=-0.5:
            heapq.heappush(FR,mx)
            break
        else:
            mx=(mx[0]+1,mx[1],mx[2]+1)
            heapq.heappush(FR,mx)
            
    for a,b,c in list(FR):
        A[b]-=c

    A.sort()
    result=[a*f for a,f in zip(A,F)]
    return max(result)
        
print(main())

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop

n,k=map(int,input().split())
a=list(input().split())
b=list(input().split())
pq=[]
for i in range(n):
    heappush(pq,(int(a[i])*int(b[i])*-1,a[i],b[i]))

for i in range(k):
    q=heappop(pq)
    new1=(int(q[1])-1)*int(q[2])*-1
    new2=str(int(q[1])-1)
    heappush(pq,(new1,new2,q[2]))

cnt=0
for i in range(n):
    q=heappop(pq)
    if cnt>q[0]:
        cnt=q[0]

print(cnt*-1)

Submission status: Wrong Answer

Solution code:
import heapq
N , K = map(int, input().split())
A = list(map(lambda x: (-1) * int(x), input().split()))
F = sorted(list(map(int, input().split())))

heapq.heapify(A)
for i in range(K):
  tmp_min = heapq.heappop(A)
  if tmp_min >= 0:
    heapq.heappush(A, (-1) * (-tmp_min))
    break
  heapq.heappush(A, (-1) * (-tmp_min - 1))

list.sort(A)
print(A)
print(F)
ans = [0] * N
for i in range(N):
  ans[i] = -A[i] * F[i]
print(max(ans))

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:
    break
  prev = k

index = max([i - 1 - (m - M + i + 1), 0])
if prev == 0:
  print(0)
else:
  print(prev * C[index])

Submission status: Wrong Answer

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

sum = 0
flag = 0
for i in range(N):
    if(flag == 0 and (A[i] -K) <  0 ):
        K = K - A[i]
    elif(flag == 0 and (A[i] - K) > 0):
        sum = (A[i] - K) * F[i]
        K = 0
    else:
        sum = A[i] * F[i]

print(sum)

Submission status: Wrong Answer

Solution code:
import heapq

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)
h = [(-fi, ai*fi, ai) for ai, fi in zip(a,f)]

heapq.heapify(h)

while k:
    (fi, ci, ai) = heapq.heappop(h)
    if ai == 0:
        break
    if k > ai:
        heapq.heappush(h, (-fi, 0, 0))
        k -= ai
    else:
        heapq.heappush(h, (-fi, (ai-k)*fi, ai-k))
        k= 0
        break

(fi, ai, ci) = heapq.heappop(h)
print(ci)

Submission status: Wrong Answer

Solution code:
from math import ceil 
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 = ceil(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(max(int(ans),0))

Submission status: Wrong Answer

Solution code:
import numpy as np

n, k = map(int, input().split())
a = list(int(i) for i in input().split())
f = list(int(i) for i in input().split())
sorted(a, reverse=True)
sorted(f, reverse=True)
a = np.array(a)
f = np.array(f)
for i in range(n):
    if a[i] < k:
        k -= a[i]
        a[i] = 0
        print(k)
    else:
        a[i] = a[i] - k
        break

ans = min(a*f)
print(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(reverse=True)
F.sort()

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

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:
    break
  prev = k

index = max([i - 1 - (m - M + i), 0])
if prev == 0:
  print(0)
else:
  print(prev * C[index])

Submission status: Wrong Answer

Solution code:
def resolve():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    F = list(map(int,input().split()))
    
    A.sort()
    F.sort(reverse=True)
    import heapq
    q = [((-1)*A[i]*F[i],A[i]) for i in range(N)]
    heapq.heapify(q)
    for _ in range(K):
        s,a = q[0]
        if s == 0:
            break
        heapq.heappushpop(q,(s*(a-1)//a,a-1))
    
    print(q[0][0]*(-1))

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:
# import sys
import numpy as np

import itertools
import heapq as hq


N, K = list(map(int, input().split(" ")))
A = np.sort(list(map(int, input().split(" "))))

m = np.min(A)
for i in range(len(A))[::-1]:
    move = min(K, A[i] - m)
    K -= move
    A[i] -= move


F = np.sort(list(map(int, input().split(" "))))[::-1]
S = A * F

heap = [(-s, a, f) for s, a, f in zip(S, A, F)]

hq.heapify(heap)

for i in range(K):
    s, a, f = hq.heappop(heap)
    if a != 0:
        a -= 1
    s = (a * f)
    hq.heappush(heap, (-s, a, f))

s, a, f = hq.heappop(heap)
print(-s)

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)
F = sorted(F, reverse=True)
count = [0 for elem in A] #
mul = [A[i]*F[i] for i in range(N)]

if K >= sum(A)*N:
    print(0)
    exit()

ma = 10**12
mi = 0
tgt = mi + (ma - mi)//2
while 1:
    tgt = mi + (ma - mi)//2
    num = 0
    for i in range(N):
        tmp = (mul[i] - tgt + F[i] - 1) // F[i]
        if tmp < 0:
            tmp = 0
        num += tmp
    if ma == mi:
        print(ma)
        exit()
    if (ma-mi) <= 10:
        break
    if num < tgt:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2

for i in range(N):
    tmp = (mul[i] - ma + F[i] - 1) // F[i]
    if tmp < 0:
        tmp = 0
    mul[i] -= F[i]*tmp
    K -= tmp
for k in range(K):
    idx = mul.index(max(mul))
    if mul[idx] == 0:
        break
    mul[idx] -= F[idx]
    count[idx] += 1
print(max(mul))

Submission status: Wrong Answer

Solution code:
import sys
import heapq
input = sys.stdin.readline

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)
res = 0
sa = sum(a)
l = 0
r = sa - K
m = int((l + r) / 2)
c = 0
def check(x):
  k = K + 0
  for i in range(N):
    if a[i] > x:
      k -= a[i] - x
    if k < 0:
      return False
  return True
while c <= 64:
  m = int((l + r) / 2)
  if check(m) == True:
    r = m
  else:
    l = m
  c += 1
rr = float("inf")
for _ in range(10):
  m += 3
  for i in range(N):
    if a[i] > m:
      K -= abs(m - a[i])
      a[i] = m
  a.sort()
  dp = [0] * N
  for i in range(N):
    dp[i] = (-a[i] * f[i], i)
  heapq.heapify(dp)
  for i in range(K):
    p = heapq.heappop(dp)
    if p[0] < 0 and i < N:
      p = (-(a[i] - 1) * f[i], i)
    heapq.heappush(dp, p)
  for i in range(N):
    res = max(res, -dp[i][0])
  rr = min(res, rr)
print(rr)

Submission status: Wrong Answer

Solution code:
i = list(map(int, input().split()))
N, K = i[0], i[1]
A = list(map(int, input().split()))
F = list(map(int, input().split()))

ave_A = sum(A) / len(A)
big_A = sorted([a for a in A if a > ave_A])
A = list(set(A) - set(big_A))

while K > 0:
    for a in big_A:
        p = a
        while p > ave_A:
            p -= 1
            K -= 1
        A.append(p)
    ave_A = sum(A) / len(A)
    big_A = sorted([a for a in A if a > ave_A])
    if big_A == []:
        A[0] -= 1
        K -= 1
        big_A = sorted([a for a in A if a > ave_A])
    A = list(set(A) - set(big_A))
    zero_count = A.count(0)

ans = sorted(F)[zero_count] * max(A)
if ans < 0:
    print(0)
else:
    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 k == 0:
    print(right)
else:
    if bit == 1:
        print(left)
    else:
        print(right)

Submission status: Wrong Answer

Solution code:
# E 
def calc():
    # K > all cost
    all_cost = 0
    for i in A_list:
        all_cost += i
    if K > all_cost:
        print(0)
        return
    
    # training
    ans_list = []
    for index, a in enumerate(A_list):
        ans_list.append(a*F_list[index])

    
    for k in range(K+1):
        ma = max(ans_list)
        for index, a in enumerate(ans_list):
            if a == ma:
                A_list[index] += -1
                ans_list[index] = A_list[index]*F_list[index]
                break


    ans_list = []
    for index, a in enumerate(A_list):
        ans_list.append(a*F_list[index])

    print(max(ans_list))


if __name__ == "__main__":
    N, K = map(int, input().split())
    A_list = [int(x) for x in input().split()]
    F_list = [int(x) for x in input().split()]
    calc()

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

import heapq
heapq.heapify(time)

while k > 0:
    m = heapq.heappop(time)
    val = m[0] * (-1)
    j = m[1]

    m2 = heapq.heappop(time)
    val2 = m2[0] * (-1)
    j2 = m2[1]
    
    while val >= val2 and k > 0:
        if a[j] != 0:
            a[j] -= 1
            k -= 1
            val = a[j] * f[j]            
    heapq.heappush(time, [val * (-1), j])
    heapq.heappush(time, [val2 * (-1), j2])
    if a[j] == 0:
        break
ans = heapq.heappop(time)
print( ans[0] * (-1) )

Submission status: Wrong Answer

Solution code:
[n,k]=list(map(int,input().split()))
alist=list(map(int,input().split()))
flist=list(map(int,input().split()))
alist.sort()
flist.sort()
flist.reverse()
clist=[]
if k>=sum(alist):
	print("0")

else:
	for i in range(n):
		clist.append(alist[i]*flist[i])


	while k>0:
		seiseki=max(clist)
		warumono=clist.index(seiseki)
		alist[warumono]=alist[warumono]-1
		k-=1

	seiseki=max(clist)
	print(int(seiseki))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A_data = list(map(int, input().split()))
F_data = list(map(int, input().split()))

A_data.sort(reverse=True)
F_data.sort(reverse=True)

index=0
while(0 < K and index < len(A_data)):
    if A_data[index] < K:
        if 0 < A_data[index]:
            K -= A_data[index]
            A_data[index] = 0
    else:
        A_data[index] -= K
        K = 0 
    index += 1

combined = [x * y for (x, y) in zip(A_data, F_data)]
combined.sort(reverse=True)
print(combined[0])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop, heapify

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
F=map(int, sys.stdin.readline().split())

A.sort()
F.sort(reverse=True)
c=N/K
for i,a in enumerate(A):
    if A[i]-c<=0:
        A[i]=0
        K-=A[i]
    else:
        A[i]=A[i]-c
        K-=c

hq=[]

for x,y in zip(A,F):
    heappush( hq,(-1*x*y,x,y) )


while 0<K:
    v=heappop(hq)
    x=v[1]
    y=v[2]
    x-=1
    K-=1
    if x*y==0:
        print 0
        quit()
    heappush( hq,(-1*x*y,x,y) )

print hq[0][0]*-1

Submission status: Wrong Answer

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

cnt=0
for i in range(n):
    cnt+=a[i]
    if cnt<k:
        a[i]=0
    else:
        a[i]=cnt-k
        break
ans=0
for i in range(n):
    ans+=a[i]*f[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N,K = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]

list.sort(A)
list.sort(F,reverse=True)
npA = np.array(A)
npF = np.array(F)
print(npA)
print(npF)

mul = (npA * npF).tolist()

count = 0

while(1):
    index = mul.index(max(mul))
    count += 1
    npA[index] -= 1
    mul[index] -= npF[index]
    if count == K:
        index = mul.index(max(mul))
        print(npA[index]*npF[index])
        sys.exit()
    if max(mul) <= 0:
        print('0')
        sys.exit()

Submission status: Wrong Answer

Solution code:
i = list(map(int, input().split()))
N, K = i[0], i[1]
A = list(map(int, input().split()))
F = list(map(int, input().split()))

ave_A = sum(A) / len(A)
big_A = sorted([a for a in A if a > ave_A])
A = list(set(A) - set(big_A))

while K > 0:
    for a in big_A:
        p = a
        while p > ave_A:
            p -= 1
            K -= 1
        A.append(p)
    ave_A = sum(A) / len(A)
    big_A = sorted([a for a in A if a > ave_A])
    if big_A == []:
        A[0] -= 1
        K -= 1
        big_A = sorted([a for a in A if a > ave_A])
    A = list(set(A) - set(big_A))
    zero_count = A.count(0)

print(sorted(F)[zero_count] * max(A))

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) & (max(l) > 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:
N, K =map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
count = 0
A.sort()
F.sort()
for i in range(N):
  count += A[i]*F[N-i-1]
for j in range(N):
  if A[j]>=K:
    count -= F[N-j-1]*K
    break
  elif A[j]<K:
    count -= F[N-j-1]*(A[j])
    K -= A[j]
print(count)

Submission status: Wrong Answer

Solution code:
from math import ceil 
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 = ceil(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]=list(map(int,input().split()))
alist=list(map(int,input().split()))
flist=list(map(int,input().split()))
alist.sort()
flist.sort()
flist.reverse()
clist=[]
for i in range(n):
	clist.append(alist[i]*flist[i])


while k>0:
	seiseki=max(clist)
	warumono=clist.index(seiseki)
	alist[warumono]=alist[warumono]-1
	k-=1

seiseki=max(clist)
print(int(seiseki))

Submission status: Wrong Answer

Solution code:
N,K= input().split()
N = int(N)
K = int(K)

A = input().split()
F = input().split()

A = [int(i) for i in A]
F = [int(i) for i in F]

A.sort()
F.sort(reverse=True)
ma = [a*f for a,f in zip(A,F)]
for i in range(K+1):
  t = ma.index(max(ma))
  A[t] -= 1
  ma[t] = A[t] * F[t]
print(max(ma))

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
width = 2 ** (big-1)
if sum(a) <= k:
  print(0)
else:
  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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  la=LI()
  lb=LI()

  la.sort(reverse=True)
  lb.sort()

  while len(la)!=0:
    a=la.pop()
    if a<=k:
      k-=a
    else:
      a-=k
      la.append(a)
      break

  if len(la)==0:
    return 0

  la.sort(reverse=True)

  ans=0
  for i,x in enumerate(la):
    y=lb[i]
    ans+=x*y

  return ans

# main()
print(main())

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, 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)
count = [0 for elem in A] #
mul = [A[i]*F[i] for i in range(N)]
#print(mul)

if K >= sum(A)*N:
    print(0)
    exit()

ma = 10**12
mi = 0
tgt = mi + (ma - mi)//2
while 1:
    tgt = mi + (ma - mi)//2
    #print("tgt:{},{},{}".format(tgt,ma,mi))
    num = 0
    for i in range(N):
        tmp = (mul[i] - tgt + F[i] - 1) // F[i]
        if tmp < 0:
            tmp = 0
        num += tmp
    if ma == mi:
        print(ma)
        exit()
    if (ma-mi) <= 10:
        break
    #tmp = tgt
    if num < tgt:
        ma = mi + (ma - mi)//2 - 0
    else:
        mi = mi + (ma - mi)//2 + 0

#print(ma)

for i in range(N):
    tmp = (mul[i] - ma + F[i] - 1) // F[i]
    mul[i] -= F[i]*tmp
    K -= tmp
for k in range(K):
    idx = mul.index(max(mul))
    if mul[idx] == 0:
        break
    mul[idx] -= F[idx]
    count[idx] += 1
print(max(mul))
#print(count)

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)
nokori = K
zcnt = 0
for i in range(N):
    #print("A", A[i], nokori)
    if A[i] < nokori:
        nokori -= A[i]
        A[i] = 0
        zcnt += 1
    elif nokori > 0:
        A[i] -= nokori
        nokori = 0
        break
    else:
        break
A = A[zcnt:]
A.sort()
#print(A)

F.sort(reverse=True)
F = F[zcnt:]
#print(F)

m = 0
for i in range(N-zcnt):
    m = max(m, A[i]*F[i])

print(m)

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:
    M = S - 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 = sum(A[i] for i in range(N) if W[i]) - 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 sys
input = sys.stdin.readline

n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
f.sort(reverse=True)
ans=0
i=0
a.sort()
while k>0:
    if a[i]<=k:
        k-=a[i]
        a[i]=0
        i+=1
    else:
        a[i]-=k
        break
    if a[-1]==0:
        break
for _ in range(n):
    ans=max(ans,a[_]*f[_])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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


def check(m, k, vs):
    s = 0
    for x, y, v in vs:
        if v >= m:
            s += (v - m + y - 1) // y
    return s <= k


n, k = read_i()
ls0 = sorted(read_i())
ls1 = sorted(read_i(), reverse=True)
if sum(ls0) <= k:
    print(0)
    exit()

vs = [(x, y, x * y) for x, y in zip(ls0, ls1)]

lo = 0
hi = sum(ls0)
while hi - lo > 1:
    mid = (lo + hi) // 2
    if check(mid, k, vs):
        hi = mid
    else:
        lo = mid
print(hi)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  la=LI()
  lb=LI()

  la.sort(reverse=True)
  lb.sort()

  while len(la)!=0:
    a=la.pop()
    if a<=k:
      k-=a
    else:
      a-=k
      la.append(a)
      break

  if len(la)==0:
    return 0

  la.sort(reverse=True)

  print(la)
  print(lb)
  ans=0
  for i,x in enumerate(la):
    y=lb[i]
    ans+=x*y

  return ans

# main()
print(main())

Submission status: Wrong Answer

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

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

left = 0
right = max(kaketa)

while True:
    jiku = (left+right)//2
    kaisuu = 0
    for i in range(n):
        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())
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)*max(F)
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)