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:
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n,k = mi()
    a = li()
    f = li()
    a = sorted(a,reverse=True)
    f.sort()
    su = 0
    for i in a:
        su+=i
    s = su-k
    if s <=0:
        print(0)
        exit()
    
    gyaku = np.array(f,dtype=np.float64)
    t = np.reciprocal(gyaku/sum(gyaku))
    ideal = (s*(t/sum(t))).astype("int64")
    need = 0
    for i in range(n):
        need+=max(a[i]-ideal[i],0)
    need -= k
    ad = (need*(t/sum(t))).astype("int64")
    ans = ideal+ad
    need-=sum(ad)
    for i in range(need):
        ans[i]+=1
    
    ans = ans*np.array(f)
    print(max(ans))

    


main()

Submission status: Wrong Answer

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

def cnt(ans):
    rt=0
    for i in range(n):
        rt+=a[i]-int(ans//f[i])
    return rt

lans,rans=0,max(a[i]*f[i] for i in range(n))
while 1:
    if rans-lans<=1:
        break
    mans=(rans+lans+1)//2
    if cnt(mans)<=k:
        rans=mans
    else:
        lans=mans
if rans==lans:
    print(rans)
else:
    if cnt(lans)>k:
        print(rans)
    else:
        print(lans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
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)
    ng=0
    
    def check(a,mid,k):
        a=array(a)
        if sum(a[a>mid]-mid)<=k:
            return 1
        else:
            return 0
            
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if check(a,mid,k):
            ok=mid
        else:
            ng=mid
        #print(mid)
    a=array([ok if i>=ok else i for i in a])
    print(max(a*array(b)))

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()
f.sort()
f.reverse()

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

Submission status: Wrong Answer

Solution code:

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

tk=k

a.sort()
l.sort()
l=l[::-1]

bd=((sum(a)-k)*sum(l))//(n*n)+1
#print(bd)

import sys
from heapq import *
if sum(a)<=k:
	print(0)
	sys.exit()

h=[]
for i in range(n):
	heappush(h,(-a[i]*l[i], a[i],l[i]))
#print(h)
while(tk>0):
	t=heappop(h)
	if -t[0]>bd and tk>0:
		td=min(t[1],-(-((-t[0])-bd)//t[2]))
		tk-=td
		#print(-(t[1]-td)*t[2],t[1]-td,t[2])
		heappush(h,(-(t[1]-td)*t[2],t[1]-td,t[2]))
	elif tk>0:
		td=min(t[1],tk//n)
		tk-=td
		#print(-(t[1]-td)*t[2],t[1]-td,t[2])
		heappush(h,(-(t[1]-td)*t[2],t[1]-td,t[2]))
	else:
		heappush(h,t)
		break
	#print(tk)


#for i in range(n):
	#print(heappop(h))

print(-heappop(h)[0])

Submission status: Wrong Answer

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

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

cost = [A[i] * F[i] for i in range(N)]
ng = -1
ok = 10**6
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:
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)[::-1]
# 二部探索法　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 = input().split()
f = input().split()

a = [int(x) for x in a]
f = [int(x) for x in f]

a.sort()
f.sort()

a = a[::-1]
tmp = 0
time_max = 0

for i in range(k):
    time_max = 0
    for j in range(n):
        time_j = a[j]*f[j]
        if time_max < time_j:
            time_max = time_j
            tmp = j
        if time_max == 0:
            break
    if time_max == 0:
        break
    a[tmp] = a[tmp] - 1

time_max = 0
for j in range(n):
    time_j = a[j]*f[j]
    if time_max < time_j:
        time_max = time_j

print(a, f)
print(time_max)

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

list.sort(A)
list.sort(F,reverse=True)
# print(A)
# print(F)
count = 0
for n in range(N):
    if (K-count) >= A[n]:
        count += A[n]
        A[n] = 0
    else:
        A[n] -= K-count
        count = K
    if count == K:
        break
# print(A)
sum = 0
for i in range(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()))
l=list(map(int,input().split()))

tk=k

a.sort()
l.sort()
l=l[::-1]

bd=((sum(a)-k)*sum(l))//(n*n)+1
#print(bd)

from heapq import *
h=[]
for i in range(n):
	heappush(h,(-a[i]*l[i], a[i],l[i]))
#print(h)
while(tk>0):
	t=heappop(h)
	if -t[0]>bd and tk>0:
		td=min(t[1],-(-((-t[0])-bd)//t[2]))
		tk-=td
		#print(-(t[1]-td)*t[2],t[1]-td,t[2])
		heappush(h,(-(t[1]-td)*t[2],t[1]-td,t[2]))
	elif tk>0:
		td=min(t[1],1)
		tk-=td
		#print(-(t[1]-td)*t[2],t[1]-td,t[2])
		heappush(h,(-(t[1]-td)*t[2],t[1]-td,t[2]))
	else:
		heappush(h,t)
		break
	#print(tk)


#for i in range(n):
	#print(heappop(h))

print(-heappop(h)[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()))

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

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

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

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

Submission status: Wrong Answer

Solution code:
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
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)
maxi = 0
for i in range(N):
    maxi = max(maxi,A[i]*F[i])
start=0
end = maxi
while True:
    count = 0
    value = (start+end)//2
    for i in range(N):
        count += max(0,A[i]-value//F[i])
    if count == K:
        break
    elif count > K :
        if 2 > end-start:
            value +=1
            break
        start = value
    else:
        if 2 > end-start:
            break
        end = value
print(value)

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()))
f.sort()

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

heapq.heapify(a)

for i in range(k):
    memo = heapq.heappop(a)
    heapq.heappush(a, memo+1)

ans = 0
for i in range(n):
    memo2 = heapq.heappop(a)
    memo3 = f[i] * memo2 *(-1)
    ans = max(ans,memo3)

print(ans)

Submission status: Wrong Answer

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

a_list.sort()
f_list.sort()


for i in range(k):  
  max_score = 0
  max_index = 0
  for j in range(n):
    score = a_list[j] * f_list[n - j - 1]
    if score > max_score:
      max_score = score
      max_index = j
      
  a_list[max_index] -= 1
  if a_list[max_index - 1] > a_list[max_index]:
    a_list[max_index - 1], a_list[max_index] = a_list[max_index], a_list[max_index - 1]
  
  if max_score == 0:
    print(0)
    break

else:
  max_score = 0
  max_index = 0
  for j in range(n):
    score = a_list[j] * f_list[n - j - 1]
    if score > max_score:
      max_score = score
      max_index = j
  print(max_score)

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)

cost = [A[i] * F[i] for i in range(N)]
ng = -1
ok = 10**6
while ok - ng > 1 :
    mid = (ok + ng) // 2
    k = 0
    for i in range(N) :
        if cost[i] <= mid :
            continue
        k += (cost[i] - mid + F[i] - 1) // F[i]

    if k <= K :
        ok = mid
    else :
        ng = mid
        
print(ok)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
ok = max(a)*max(f)
ng = -1

while ok-ng >1:
    mid = (ok+ng)//2
    t = 0
    for i in range(n):
        if mid%f[i] == 0:
            t += a[i]-mid//f[i]
        else:
            t += int(a[i]-mid//f[i])
    if t >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()))
X =list(map(lambda x: 1/x, F))
p=sum(X)
c=sum(A)
if sum(A)-k>0:
    ans=((sum(A)-k)//p)+1
else:
    ans=0
print(ans//1)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

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

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

while K>1:
    herasu = K//2
    AF = [a*f for a, f in zip(A, F)]
    IAF = enumerate(AF)
    IAF = sorted(IAF, key=itemgetter(1), reverse=True)
    for i, _ in IAF[:herasu]:
        A[i] -= 1
    K -= herasu

if K:
    AF = [a*f for a, f in zip(A, F)]
    IAF = enumerate(AF)
    IAF = sorted(IAF, key=itemgetter(1), reverse=True)
    for i, _ in IAF[:1]:
        A[i] -= 1

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

print(max(AF))

Submission status: Wrong Answer

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

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

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

def nasu(n):
  ans = 0
  for i in range(N):
    ans += max(0, A[i] - (n // F[i]))
  if ans <= K:
    return True
  else:
    return False

def hersCode():
  ok = M
  ng = -1
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if nasu(mid):
      ok = mid
    else:
      ng = mid
  return ok
print(A)
print(F)
print(hersCode())

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A =list(map(int,input().split()))
F =list(map(int,input().split()))
X =list(map(lambda x: 1/x, F))
p=sum(X)
c=sum(A)
if sum(A)-k>0:
    ans=((sum(A)-k)//p)+1
else:
    ans=0
print(int(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()))
X =list(map(lambda x: 1/x, F))
p=sum(X)
c=sum(A)
if sum(A)-k>0:
    ans=((sum(A)-k)//p)+1
else:
    ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

if - sum(a) < - k:
    print(0)
else:
    heapq.heapify(a)
    while k < 0:
        v = heapq.heappop(a)
        if v > k:
            v -= k
            k = 0
            heapq.heappush(a, v)
        else:
            v = 0
            k -= v
            heapq.heappush(a, v)
    print(b[0] * - heapq.heappop(a))

Submission status: Wrong Answer

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


for i in range(k):
  a_list.sort()
  f_list.sort()
  
  max_score = 0
  max_index = 0
  for j in range(n):
    score = a_list[j] * f_list[n - j - 1]
    if score > max_score:
      max_score = score
      max_index = j
  a_list[max_index] -= 1
  
  if max_score == 0:
    break

else:
  a_list.sort()
  f_list.sort()
  max_score = 0
  max_index = 0
  for j in range(n):
    score = a_list[j] * f_list[n - j - 1]
    if score > max_score:
      max_score = score
      max_index = j
  print(max_score)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = sorted([int(a) for a in input().split()])
F = sorted([int(a) for a in input().split()])[::-1]
l = -1
r = 2*10**11
while r-l > 1:
    m = (l+r)//2
    if sum([max(0, A[i] - m//F[i]) for i in range(N)]) <= K:
        r = m
    else:
        l = m
print(r)

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=0
r=A[-1]*F[-1]
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()))
f = list(map(int, input().split()))

import math
A = sum(a)
F = 0
for _f in f:
    F += 1.0 / _f
print(math.ceil((A - k) / F))

Submission status: Wrong Answer

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


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

  if a_sum < 1:
    print(0)
    return

  a_vals = [int(a_sum * v / f_sum) for v in f_rates]
  a_vals.sort()
  f_vals.sort(reverse=True)
  remain = a_sum - sum(a_vals)

  if remain == 0:
    print(max(a * f for a, f in zip(a_vals, f_vals)))
  else:
    costs = [(a + 1) * f for a, f in zip(a_vals, f_vals)]
    costs.sort()
    print(costs[remain - 1])


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()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1!=ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    h+=a[i]-(mid//f[i])
  if h<=k:ok=mid
  else:ng=mid
print(ok)

Submission status: Wrong Answer

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

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

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

def nasu(n):
  ans = 0
  for i in range(N):
    ans += A[i] - (n // F[i])
  if ans <= K:
    return True
  else:
    return False

def hersCode():
  ok = M
  ng = -1
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if nasu(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(hersCode())

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

    a.sort()
    f = sorted(f, reverse=True)
    # l = []
    # for i in range(n):
    #     l.append(a[i] * f[i])
    # print(*l)
    suma = sum(a)

    def ok(v):
        cnt = 0
        sa = 0
        for i in range(n):
            # t = a[i] * f[i]
            # if t <= v:
            #     continue
            # print(t,v,a[i],cnt)
            # cnt += math.ceil((t - v) / a[i])
            # if (t-v) % a[i]:
            #     cnt += (t - v) // a[i]
            # else:
            #     cnt += ((t - v) // a[i]) + 1
            x = v // f[i]
            sa += x
        if suma - k <= sa:
            return True
        else:
            return False


        
        # if cnt <= k:
        #     return True
        # else:
        #     return False


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

    
            
    

    

    

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

left = -1
right = 100


while right - left > 1:
    mid = left + (right - left) // 2


    train = k
    for i in range(n):
        req = mid // f[i]
        if req < a[i]:
            train -= a[i] - req


    if train >= 0:
        right = mid
    else:
        left = mid



print(right)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
dp = []
for i in range(N):
    dp.append((A[i]*F[i], F[i]))
dp.sort(key=lambda x: x[0], reverse=True)
total = sum(A)
res = dp[0][0]
if K >= total:
    print(0)
    exit()
l, r = 0, res
while l < r:
    m = (l + r) // 2
    cnt = 0
    maxs = 0
    for i in range(N):
        cur = max(0, dp[i][0] - m)
        cnt += cur // dp[i][1] + int(cur % dp[i][1] > 0)
        maxs = max(maxs, cur)
    if cnt > K: l = m + 1
    else:
        r = m
        res = min(res, maxs)
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()))
a.sort()
for i in range(n):
    if a[n-i-1]<=k:
        k-=a[n-i-1]
        a[n-i-1]=0
    else:
        k=0
        a[n-i-1]-=k
    if k==0:
        break
a.sort()
f.sort(reverse=True)
ans=0
for i in range(n):
    ans=max(ans,a[i]*f[i])
print(ans)

Submission status: Wrong Answer

Solution code:
stats = [int(i) for i in input().split()]
peeps = sorted([int(i) for i in input().split()])
foods = sorted([int(i) for i in input().split()], reverse = True)
k = stats[1]
i = 0


while k > 0 and i<len(peeps):
    while peeps[i]>0:
        peeps[i] -= 1
        k -= 1
        if (k<=0):
            break
    i += 1

print(sum(peeps[i]*foods[i] for i in range(len(peeps))))

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()
for i in range(n):
    if a[n-i-1]<=k:
        k-=a[n-i-1]
        a[n-i-1]=0
    else:
        k=0
        a[n-i-1]-=k
    if k==0:
        break
a.sort()
f.sort(reverse=True)
ans=0
for i in range(n):
    ans+=a[i]*f[i]
print(a[-1]*f[-1])

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
for _ in range(K):
    if A_data[index] <= 0:
        index +=1
    if len(A_data) <= index:
        break
    
    A_data[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:
import numpy as np


def solve(n, k, aaa, fff):
    aaa = np.sort(aaa)
    fff = np.sort(fff)[::-1]

    l = 0
    r = 10 ** 12 + 1
    while l < r - 1:
        m = (l + r) // 2
        req = np.clip(aaa - m // fff, 0, None).sum()
        # print(aaa, m // fff, req)
        if req > k:
            l = m + 1
        else:
            r = m
    return l


n, k = list(map(int, input().split()))
aaa = np.array(list(map(int, input().split())), dtype=np.int64)
fff = np.array(list(map(int, input().split())), dtype=np.int64)

print(solve(n, k, aaa, fff))

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)
    for i in range(n):
        if a[i]<=k:
            k-=a[i]
            a[i]=0
        else:
            a[i]-=k
            k=0
            break
            
    print(dot(array(a),array(b)))
    
    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a2=a
k2=k
f=list(map(int,input().split()))
a.sort()
for i in range(n):
    if a[n-i-1]<=k:
        k-=a[n-i-1]
        a[n-i-1]=0
    else:
        k=0
        a[n-i-1]-=k
    if k==0:
        break
a.sort()
f.sort(reverse=True)
ans=0
for i in range(n):
    ans+=a[i]*f[i]
for i in range(n):
    if a2[i]<=k:
        a2[i]=0
        k2-=a2[i]
    else:
        k2=0
        a2[i]-=k2
    if k2==0:
        break
ans2=0
for i in range(n):
    ans2+=a2[i]*f[i]
print(min(ans,ans2))

Submission status: Wrong Answer

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

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

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

def judge(n):
    score = 0
    for i in range(N):
        score += max(A[i] - n//F[i],0)
    return score<=K

if judge(0):
    print(0)
else:
    def bisect(l,r):
        while r-l>1:
            if judge((l+r)//2):
                r = (l+r)//2
            else:
                l = (1+r)//2
        return r

    print(bisect(0,M))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = sorted([int(a) for a in input().split()])
F = sorted([int(a) for a in input().split()])[::-1]
l = -1
r = sum(A)
while r-l > 1:
    m = (l+r)//2
    if sum([max(0, A[i] - m//F[i]) for i in range(N)]) <= K:
        r = m
    else:
        l = m
print(r)

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_jun = []
# num = 0
# for i in range(n):
#     num += a[i]
#     a_jun.append(num)

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

a = a[::-1]
a = np.array(a)
f = np.array(f)
sum = sum(a * f)
print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,k = map(int,input().split())
al = list(map(int,input().split()))
fl = list(map(int,input().split()))
fl.sort(reverse=1)
al.sort()
for i in range(n):
  if al[i] < k:
    k -= al[i]
    al[i] = 0
  else:
    al[i] -= k
    k = 0
    break
print(np.dot(al,fl))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))

def check(mid, k, pairs):
    tmp = 0
    for pair in pairs:
        a,b = pair
        kari_a = mid // b
        tmp += max(a - kari_a, 0)

    if tmp <= k:
        return True
    else:
        return False


def solve():
    n, k = getList()
    cap = getList()
    foods = getList()
    cap.sort()
    foods.sort(reverse=True)
    h = []
    pairs = [(a, b) for a, b in zip(cap, foods)]
    ansmn = 0
    ansmx = 10**7
    while(ansmx - ansmn > 1):
        mid = (ansmn + ansmx) // 2
        res = check(mid, k, pairs)
        if res:
            ansmx = mid
        else:
            ansmn = mid


    if check(ansmn, k, pairs):
        print(ansmn)
    else:
        print(ansmx)

def main():
    solve()


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()
for i in range(n):
    if a[n-i-1]<=k:
        k-=a[n-i-1]
        a[n-i-1]=0
    else:
        k=0
        a[n-i-1]-=k
    if k==0:
        break
a.sort()
f.sort(reverse=True)
ans=0
for i in range(n):
    ans+=a[i]*f[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


def solve(n, k, aaa, fff):
    lim = sum(aaa) - k

    l = 0
    r = 10 ** 12 + 1
    while l < r - 1:
        m = (l + r) // 2
        req = (m // fff).sum()
        if req < lim:
            l = m + 1
        else:
            r = m
    return l


n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
fff = np.array(list(map(int, input().split())), dtype=np.int64)

print(solve(n, k, aaa, fff))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    f = LI()
    a.sort()
    f.sort(reverse = True)
    M = a[0]*f[-1]+10
    l = -1
    r = M
    while r-l > 1:
        m = (l+r)>>1
        s = 0
        for i in range(n):
            s += max(0,math.ceil(a[i]-m/f[i]))
            if s > k:
                l = m
                break
        else:
            r = m
    print(r)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
get = lambda: int(raw_input().strip())
gets = lambda: map(int, raw_input().strip().split())

# fi = open('sample3.in', 'r')
# raw_input = fi.readline

N, K = gets()
A = sorted(gets())
F = sorted(gets())[::-1]

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

Submission status: Time Limit Exceeded

Solution code:
def is_good(mid, key):
    return sum(max(0, a - mid // f) for a, f in zip(A, F)) <= key


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


N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
A_sum = sum(A)
ans = binary_search(-1, max(a * f for a, f in zip(A, F)), K)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from math import ceil
    n, k = map(int, input().split())
    A = sorted(map(int, input().split()))
    F = sorted(map(int, input().split()))
    A.reverse()
    ok = max(a * f for a, f in zip(A, F))
    ng = -1
    while ok - ng != 1:
        x = (ok + ng) // 2
        cnt = 0
        for a, f in zip(A, F):
            if a * f > x:
                cnt += ceil(a - x / f)
            if cnt > k:
                ng = x
                break
        else:
            ok = x

    print(ok)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()))
A.reverse()
ok = max(a * f for a, f in zip(A, F))
ng = -1
while ok - ng != 1:
    x = (ok + ng) // 2
    cnt = 0
    for a, f in zip(A, F):
        if a * f > x:
            cnt += ceil(a - x / f)
        if cnt > k:
            ng = x
            break
    else:
        ok = x

print(ok)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()))
A.reverse()
ok = A[0] * F[-1]
ng = -1
while ok - ng != 1:
    x = (ok + ng) // 2
    cnt = 0
    for a, f in zip(A, F):
        if a * f > x:
            cnt += ceil(a - x / f)
        if cnt > k:
            ng = x
            break
    else:
        ok = x

print(ok)