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 sys
import numpy as np
N,K=map(int,input().split())
A=np.array([int(i) for i in input().split()])
F=np.array([int(i) for i in input().split()])
A=np.sort(A)
F=np.sort(F)[::-1]

Asum=A.sum()
i=0
while True:
    i += 1
    if Asum - np.minimum(A,i//F).sum() <=K:
        print(i)
        sys.exit()

Submission status: Wrong Answer

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

ss = [[] for i in range(2)]
for i in range(2):
    ss[i] = list(map(int,input().split()))


A = ss[0]
F = ss[1]
A.sort()
F.sort()
F.reverse()

left = -1
right = max([(A[j] * F[j]) for j in range(n)])

while (right - left) > 1:
    b = [[] for i in range(n)]
    s = left + ((right - left) // 2)
    for i in range(n):
        b[i] = min(s//F[i],A[i])
    if (sum(A) - sum(b)) <= k:
        right = s 
    else:
        left = s 

print(left)

Submission status: Wrong Answer

Solution code:
import numpy as np

def is_ok(mid, k):
    s = a - mid // f
    print(s)
    s = s[s > 0].sum()
    if s <= k:
        return True
    else:
        return False

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)
a = np.array(a)
f = np.array(f)

l, r = -1, 10**12 # l:ng, r:ok
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, k):
        r = mid
    else:
        l = mid
print(r)

Submission status: Wrong Answer

Solution code:
def is_ok(mid, N, K):
    s = 0
    for i in range(N):
        s += max(A[i] - mid / F[i], 0)
        if s > K:
            return False
    return True


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)

l, r = -1, 10**12
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, N, K):
        r = mid
    else:
        l = mid
        
print(r)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if not discrete else l if left else r

def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    F=list(map(int,input().split()))
    F.sort(reverse=1)

    def check(m):
        cost=0
        for a,f in zip(A,F):
            if(a*f<=m): continue
            cost+=(a*f-m-1)//f+1
        return cost<=k

    print(bisection(-1,10**13,check,left=False))
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if not discrete else l if left else r

def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    F=list(map(int,input().split()))
    F.sort(reverse=1)

    def check(m):
        cost=0
        for a,f in zip(A,F):
            if(a*f<=m): continue
            cost+=(a*f-m-1)//f+1
        return cost<=k

    print(bisection(-1,10**12,check,left=False))
resolve()

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()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
l=0
r=10**12
x=(r+l)//2
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
    if p>k:
        return False
    else:
        return True
while l+1<r:
    if check(x):
        r=x
        x=(r+l)//2
    else:
        l=x
        x=(r+l)//2
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()))
A.sort()
F.sort(reverse=True)


def search(left, right):
    if left == right:
        return left
    mid = (left + right) // 2
    total_fix = 0
    for i in range(N):
        total_fix += max(0, A[i] - mid // F[i])

    if total_fix == K:
        return total_fix

    if total_fix > K:
        return search(min(mid + 1, int(1e12)), right)
    elif total_fix < K:
        return search(left, mid)


ans = search(0, int(1e12))
print(ans)

Submission status: Wrong Answer

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


def search(left, right):
    if left == right:
        return left
    mid = (left + right) // 2
    total_fix = 0
    for i in range(N):
        total_fix += max(0, A[i] - mid / F[i])

    if total_fix == K:
        return total_fix

    if total_fix > K:
        return search(min(mid + 1, right), right)
    elif total_fix < K:
        return search(left, max(left, mid - 1))


ans = search(0, int(1e12))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
all_0 = [0 for i in range(N)]
A.sort()
F.sort()
F.reverse()
MUL = [A[i]*F[i] for i in range(N)]
max_MUL = max(MUL)

def Gluttony(num):
    SUM = 0
    for i in range(N):
        SUM+=math.ceil(A[i]-(num/F[i]))
    if SUM<=K:
        return True
    else:
        return False

left = 0
right = max(MUL)

while left<=right:
    mid = (left+right)//2
    if Gluttony(mid):
        right = mid-1
    else:
        left = mid+1

print(left)

Submission status: Wrong Answer

Solution code:
import sys
import queue
bbn=1000000007
	
#+++++

def can_finish(time, a_c_qq, a_k):
	kc=a_k
	
	#if time==12:
	#	print(*a_c_qq)
		
	for (st,a,f) in (a_c_qq):
		if st <= time:
			return True
		
		#time => f*a' を目指す。
		#a' <= time / f が必要。
		#コストは a - (time // f)
		kc -= a - (time//f)
		#if time==12:
		#	pa((st,a,f, time,(time//f),a- (time//f),kc))
		
		if kc < 0:
			return False
		
	return True
	
		
def main():
	n, k = map(int, input().split())
	al=list(map(int, input().split()))
	fl=list(map(int, input().split()))
	
	qq=queue.PriorityQueue()
	
	al.sort(reverse=True)
	fl.sort()
	qq=[(a*f,a,f) for a,f in zip(al,fl)]
	qq.sort(reverse=True)

	#while not qq.empty():
	#	a=qq.get()
	#	pa(a)
	
	ok_max,_,_=qq[0]
	if sum(al) < k:
		return 0
	ng_min=0
	
	while ok_max - ng_min > 1:
		mid = (ok_max + ng_min)// 2
		can_do = can_finish(mid, qq, k)
		#pa((ok_max,ng_min,mid,can_do))
		if can_do:
			ok_max = mid
		else:
			ng_min = mid

	print(ok_max)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys
import queue
bbn=1000000007
	
#+++++

def can_finish(time, a_c_qq, a_k):
	kc=a_k
	
	#if time==12:
	#	print(*a_c_qq)
		
	for (st,a,f) in (a_c_qq):
		if st <= time:
			return True
		
		#time => f*a' を目指す。
		#a' <= time / f が必要。
		#コストは a - (time // f)
		kc -= a - (time//f)
		#if time==12:
		#	pa((st,a,f, time,(time//f),a- (time//f),kc))
		
		if kc < 0:
			return False
		
	return True
	
		
def main():
	n, k = map(int, input().split())
	al=list(map(int, input().split()))
	fl=list(map(int, input().split()))
	
	qq=queue.PriorityQueue()
	
	al.sort(reverse=True)
	fl.sort()
	qq=[(a*f,a,f) for a,f in zip(al,fl)]
	qq.sort(reverse=True)

	#while not qq.empty():
	#	a=qq.get()
	#	pa(a)
	
	ok_max,_,_=qq[0]
	if sum(al) < k:
		return 0
	ng_min=0
	
	while ok_max - ng_min > 1:
		mid = (ok_max + ng_min)// 2
		can_do = can_finish(mid, qq, k)
		#pa((ok_max,ng_min,mid,can_do))
		if can_do:
			ok_max = mid
		else:
			ng_min=mid

	print(ok_max)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys

def jeat(a, f, x, K):
    N = 0
    for i in range(len(a)):
        if a[i]*f[i] > x:
            N += a[i] - x // f[i]
    if N > K:
        return False
    if N <= K:
        return True

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
if K >= sum(A):
    print(0)
    sys.exit()
A.sort()
F.sort(reverse = True)
a = 0
b = 10**18
while (a<b):
    z = (a+b)//2
    if jeat(A,F,z,K) == True:
        if jeat(A,F,z-1,K) == False:
            break
        b = z-1
    else:
        if jeat(A,F,z+1,K) == True:
            z -= 1
            break
        a = z+1

print(z)

Submission status: Wrong Answer

Solution code:
import sys

def jeat(a, f, x, K):
    N = 0
    for i in range(len(a)):
        if a[i]*f[i] > x:
            N += a[i] - x // f[i]
    if N > K:
        return False
    if N <= K:
        return True

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
if K >= sum(A):
    print(0)
    sys.exit()
A.sort()
F.sort(reverse = True)
a = 0
b = 10**13
while (a<b):
    z = (a+b)//2
    if jeat(A,F,z,K) == True:
        if jeat(A,F,z-1,K) == False:
            break
        b = z-1
    else:
        if jeat(A,F,z+1,K) == True:
            z -= 1
            break
        a = z+1

print(z)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l1=sorted(l1)
l2=sorted(l2)
l2=l2[::-1]
l3=[]
for i in range(n):
  l3.append(l1[i]*l2[i])
left=0
right=10**12
while left<right:
  mid=(left+right)//2
  if mid==left:
    num=0
    for i in range(n):
      if l3[i]<=left:
        pass
      else:
        dis=l3[i]-left#いくつ減らす必要がある？
        num+=((dis-1)//l2[i])+1
    if num<=k:
      print(left,right)
      print(left)
      print(num)
      exit()
    else:
      print(right)
      exit()
  num=0
  for i in range(n):
    if l3[i]<=mid:
      pass
    else:
      dis=l3[i]-mid
      num+=((dis-1)//l2[i])+1
  if num<=k:
    right=mid
  else:
    left=mid
print(left)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l1=sorted(l1)
l2=sorted(l2)
l2=l2[::-1]
l3=[]
for i in range(n):
  l3.append(l1[i]*l2[i])
left=0
right=10**12
while left<right:
  mid=(left+right)//2
  if mid==left:
    num=k
    for i in range(n):
      if l3[i]<=left:
        pass
      else:
        dis=l3[i]-left
        num-=(dis-1)//l2[i]+1
      if num>=0:
        print(left)
        exit()
      else:
        print(right)
        exit()
  num=k
  for i in range(n):
    if l3[i]<=mid:
      pass
    else:
      dis=l3[i]-mid
      num-=(dis-1)//l2[i]+1
  if num<0:
    left=mid
  else:
    right=mid
print(left)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l1=sorted(l1)
l2=sorted(l2)
l2=l2[::-1]
l3=[]
for i in range(n):
  l3.append(l1[i]*l2[i])
left=0
right=10**12
while left<right:
  mid=(left+right)//2
  if mid==left:
    num=k
    for i in range(n):
      if l3[i]<=right:
        pass
      else:
        dis=l3[i]-right
        num-=(dis-1)//l2[i]+1
      if num>=0:
        print(right)
        exit()
      else:
        print(left)
        exit()
  num=k
  for i in range(n):
    if l3[i]<=mid:
      pass
    else:
      dis=l3[i]-mid
      num-=(dis-1)//l2[i]+1
  if num>=0:
    right=mid
  else:
    left=mid
print(left)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
af = [a[i]*f[i] for i in range(n)]
lower = 0
upper = max(af)
prev = 0
now = upper // 2
while now != prev:
  count = 0
  for i in range(n):
    if a[i]*f[i] > now:
      count += a[i] - now // f[i]
  if count <= k:
    upper = now
  else:
    lower = now
  prev = now
  now = (lower + upper) // 2 + 1

print(upper)

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()
af = [a[i]*f[i] for i in range(n)]
lower = 0
upper = max(af)
prev = 0
now = upper // 2
while now != prev:
  count = 0
  for i in range(n):
    if a[i]*f[i] > now:
      count += a[i] - now // f[i]
  if count <= k:
    upper = now
  else:
    lower = now
  prev = now
  now = (lower + upper) // 2 + 1

print(now)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)

maxT = A[-1]*F[-1] # T with no training
# use binary search to find lowest possible T
left = -1
right = maxT
while left+1< right:
    mid = (left+right)//2
    if np.maximum(0, A - (mid//F)).sum() <= K:
        right  = mid
    else:
        left = mid
print(right)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)

maxT = A[-1]*F[-1] # T with no training
# use binary search to find lowest possible T
left = -1
right = maxT + 1
while left+1< right:
    mid = (left+right)//2
    if np.maximum(0, A - (mid//F)).sum() <= K:
        right  = mid
    else:
        left = mid
print(right)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)

def how_many_K(A,F,T,K):
    """
    Returns whether the number of training sessions needed for group A with foods F to have a score equal to T is less than K
    """
    num_trains = 0
    for i in range(len(A)):
        a = A[i]
        f = F[i]
        num_trains += max(0, a-T//f)

    if num_trains > K:
        return False
    else:
        return True

maxT = A[-1]*F[-1] # T with no training
# use binary search to find lowest possible T
left = -1
right = maxT + 1
while left+1< right:
    mid = (left+right)//2
    #if how_many_K(A,F,mid,K):
    if np.maximum(0, A - (mid//F)).sum() <= K:
        right  = mid
    else:
        left = mid
print(mid)

Submission status: Wrong Answer

Solution code:
from math import ceil

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)

def how_many_K(A,F,T,K):
    """
    Returns whether the number of training sessions needed for group A with foods F to have a score equal to T is less than K
    """
    num_trains = 0
    for i in range(len(A)):
        a = A[i]
        f = F[i]
        num_trains += max(0, a-T//f)

    if num_trains > K:
        return False
    else:
        return True

maxT = A[-1]*F[-1] # T with no training
# use binary search to find lowest possible T
left = -1
right = maxT
while left+1< right:
    mid = (left+right)//2
    if how_many_K(A,F,mid,K):
        right  = mid
    else:
        left = mid
print(mid)

Submission status: Wrong Answer

Solution code:
from math import ceil

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)

def how_many_K(A,F,T,K):
    """
    Returns whether the number of training sessions needed for group A with foods F to have a score equal to T is less than K
    """
    num_trains = 0
    for i in range(len(A)):
        a = A[i]
        f = F[i]
        num_trains += a-T//f

    if num_trains > K:
        return False
    else:
        return True

maxT = A[-1]*F[-1] # T with no training
# use binary search to find lowest possible T
left = -1
right = maxT
while left+1< right:
    mid = (left+right)//2
    if how_many_K(A,F,mid,K):
        right  = mid
    else:
        left = mid
print(mid)

Submission status: Wrong Answer

Solution code:
inputs = list(map(int, input().split()))
an = list(map(int, input().split()))
fn = list(map(int, input().split()))

n = inputs[0]
k = inputs[1]

an.sort()
fn.sort(reverse=True)
muln = [an[j]*fn[j] for j in range(n)]

left = 0
right = 10**18

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

  total = sum([an[i]-int(mid/fn[i]) if mid < muln[i] else 0 for i in range(n)])

  if total < k:
    right = mid
  elif total > k:
    left = mid
  else:
    print(mid)
    exit(0)

if total < k:
  print(left)
else:
  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=sorted(a)[::-1]
f=sorted(f)

ok=(10**6)*(10**5)*2
ng=-1

import math
def isOK(val,arr,farr,k):
  s=0
  for i in range(len(arr)):
    s+=max(math.ceil(a[i]-val/f[i]),0)
  return s<=k
  
while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOK(mid,a,f,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=sorted(a)[::-1]
f=sorted(f)

ok=(10**6)*n
ng=-1

import math
def isOK(val,arr,farr,k):
  s=0
  for i in range(len(arr)):
    s+=max(math.ceil(a[i]-val/f[i]),0)
  return s<=k
  
while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOK(mid,a,f,k):
    ok=mid
  else:
    ng=mid
    
print(ok)

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    f = list(map(int, input().rstrip('\n').split()))
    f.sort(reverse=True)
    cor_v = 10 ** 13
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            t = a[i] * f[i]
            if t > bin_v:
                cost += (t - bin_v + f[i] - 1) // f[i]
        #costが制約を満たすか
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)


if __name__ == '__main__':
    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())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()
 
range_max = A[0] * F[-1] + 1
range_min = A[-1] * F[0]
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(range_min, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

Submission status: Wrong Answer

Solution code:
### D - Glutony ###
# TLE
# defでやると遅いので、

N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
F = list(map(int, input().split())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()
 
# range_max = max([i*j for i,j in zip(A,F)]) + 1
# range_min = max(min([(i-K)*j for i,j in zip(A,F)]), 0)

range_max = A[0] * F[-1]
range_min = 0

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(range_min, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

Submission status: Wrong Answer

Solution code:
# Gluttony
# AC 10/35 TLE 25/35

N, K = map(int, input().split())
A = list(map(int, input().split())) # 消化コスト
F = list(map(int, input().split())) # 食べにくさ
 
import math
 
A.sort(reverse = True)
F.sort()

range_max = max([i*j for i,j in zip(A,F)])

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K

my_range = range(0, range_max)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
node(my_range)

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.sort(reverse = True)
F.sort()
 
my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K
 
my_range = range(0, 10**10)
 
def node(lst):
    len_lst = len(lst)
    if len_lst % 2 == 0:
        mid_idx = int(len_lst/2)
    else:
        mid_idx = int(math.floor(len_lst/2))
 
    if len_lst == 1:
        print(lst[mid_idx])
        return()
 
    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)
 
node(my_range)

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

my_lambda = lambda x: sum([max(math.ceil(A[i] - x/F[i]), 0) for i in range(0, N)]) <= K

my_range = range(0, 10**6)

def node(lst):
    if len(lst) % 2 == 0:
        mid_idx = int(len(lst)/2)
    else:
        mid_idx = int(math.floor(len(lst)/2))

    if len(lst) == 1:
        print(lst[mid_idx])
        return()

    if my_lambda(lst[mid_idx-1]) == True:
        left = lst[0:mid_idx]
        node(left)
    else:
        right = lst[mid_idx:]
        node(right)

node(my_range)

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

for disused in range(0, 14+1):
    glut = [i*j for i, j in zip(A,B)]
    idx = glut.index(max(glut))
    A[idx] = A[idx] - 1


print(A)
print(B)
print(glut)
print(max(glut))

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

for disused in range(0, 14+1):
    glut = [i*j for i, j in zip(A,B)]
    idx = glut.index(max(glut))
    A[idx] = A[idx] - 1

print(max(glut))

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()
    f = list(map(int, readline().split()))
    f.sort(reverse=True)

    cor_v = 10 ** 20
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n):
            cost += ((a[i] * f[i]) - bin_v + f[i] - 1) // f[i]
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

N, K = map(int, readline().split())
A = np.array(readline().split(),np.int64)
F = np.array(readline().split(),np.int64)

A.sort()
F.sort()
F=F[::-1]
 
new_list_a = np.array(A)
new_list_f = np.array(F)
 
for _ in range(K):
  time = new_list_f * new_list_a
  number_a = np.argmax(time)
  new_list_a[number_a] = new_list_a[number_a] - 1
  
print(max(time))

Submission status: Wrong Answer

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

N, K = map(int, readline().split())
A = np.array(readline().split(),np.int64)
F = np.array(readline().split(),np.int64)

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

for i in range(K):
  time = F * A
  number_a = np.argmax(time)
  A[number_a] = A[number_a] - (i - (i - 1))
  
print(max(time))

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N, K = map(int, input().split())
new_list_a = sorted(list(map(int, input().split())), reverse=True)
new_list_f = sorted(list(map(int, input().split())))
 
new_list_a = np.array(new_list_a)
new_list_f = np.array(new_list_f)
time = new_list_f * new_list_a
 
for i in range(K):
  number_a = np.argmax(time)
  new_list_a[number_a] = new_list_a[number_a] - (i - (i - 1))
  time = new_list_f * new_list_a
  if new_list_a[number_a] == 0:
    break
  
print(max(time))

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N, K = map(int, input().split())
new_list_a = sorted(list(map(int, input().split())), reverse=True)
new_list_f = sorted(list(map(int, input().split())))
 
new_list_a = np.array(new_list_a)
new_list_f = np.array(new_list_f)
time = new_list_f * new_list_a

#修行の回数Kだけ繰り返す
#AとKの積で最大のときのインデックスを取り出す
#そのインデックスのAから１引く
for i in range(K + 1):
  number_a = np.argmax(time)
  new_list_a[number_a] = new_list_a[number_a] - (i - (i - 1))
  time = new_list_f * new_list_a
  if new_list_a[number_a] == 0:
    break
  
print(max(time))

Submission status: Wrong Answer

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

N,K = map(int,readline().split())
people = np.array(readline().split(),np.int64)
food = np.array(readline().split(),np.int64)
 
people.sort()
food.sort()
food=food[::-1]

#2分探索　Kの値で
_max = max(people)
_min = 0

while _max>_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  _K = np.maximum(0,people - mean//food).sum()
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)

Submission status: Wrong Answer

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

N,K = map(int,readline().split())
people = np.array(readline().split(),np.int64)
food = np.array(readline().split(),np.int64)
 
people.sort()
food.sort()
food=food[::-1]

#2分探索　Kの値で
_max = max(people)
_min = 0

while _max>_min:
  mean = (_max+_min)//2
  # 各人が修行をする回数の配列　負の値もでる
  K_arr = np.maximum(0,people - mean//food)
  # 総修行回数
  _K = sum(K_arr)
  if _K > K:
    _min = mean+1
  else:
    _max = mean
    
print(_max)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
list_cost =list(map(int, input().split()))
list_difficulty =list(map(int, input().split()))

workout = 0
list_difficulty.sort()
list_difficulty.reverse()

while workout < k:
    max_point = 0
    min_point = 0
    max_index = 0
    list_cost.sort()

    for index, cost in enumerate(list_cost):
        point = cost * list_difficulty[index]
        if point > max_point:
            max_point = point
            max_index = index
    if max_point == 0:
      break
    list_cost[max_index] -= 1
    workout += 1
    
print(max_point)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
list_cost =list(map(int, input().split()))
list_difficulty =list(map(int, input().split()))

workout = 0
list_difficulty.sort()
list_difficulty.reverse()
while True:
    max_point = 0
    min_point = 0
    max_index = 0
    list_cost.sort()

    for index, cost in enumerate(list_cost):
        point = cost * list_difficulty[index]
        if point > max_point:
            max_point = point
            max_index = index

    if workout <= k and max_point > 0:
        list_cost[max_index] -= 1
        workout += 1
        continue
    else:
        print(max_point)
        break