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: Time Limit Exceeded

Solution code:
from math import ceil
import numpy as np
def main():
    N, K = map(int,input().split())
    A = np.array(list(map(int,input().split())), dtype="i8")
    C = np.array(list(map(int,input().split())), dtype="i8")
    A.sort()
    A = A[::-1]
    C.sort()
    def chk(x):
        cnt = 0
        for i in range(N):
            cnt += max(ceil(A[i]-x/C[i]), 0)
            if cnt > K:
                return False
        return True
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(m):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
import numpy as np
def chk(A, C, x, K):
    cnt = 0
    for i in range(len(A)):
        cnt += max(ceil(A[i]-x/C[i]), 0)
        if cnt > K:
            return False
    return True
def main():
    N, K = map(int,input().split())
    A = np.array(list(map(int,input().split())))
    C = np.array(list(map(int,input().split())))
    A.sort()
    A = A[::-1]
    C.sort()
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(A, C, m, K):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
def chk(A, C, x, K):
    cnt = 0
    for i in range(len(A)):
        cnt += max(ceil(A[i]-x/C[i]), 0)
        if cnt > K:
            return False
    return True
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort(reverse=True)
    C.sort()
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(A, C, m, K):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort(reverse=True)
    C.sort()
    def chk(x):
        cnt = 0
        for i in range(N):
            cnt += max(ceil(A[i]-x/C[i]), 0)
            if cnt > K:
                return False
        return True
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(m):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
F_list = list(map(int, input().split()))

A_list_min = sorted(A_list)
F_list_max = sorted(F_list, reverse=True)

first_OK = 10**12

def is_ok(arg):
    check_cnt = 0
    return_flag = 0
    for i in range(N):
        temp = A_list_min[i] - arg//F_list_max[i]
        if temp > 0:
            check_cnt += A_list_min[i] - arg//F_list_max[i]
    if check_cnt <= K:
        return_flag = 1
    else:
        return_flag = 0
    return return_flag

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

print(bisect(-1, first_OK))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
F_list = list(map(int, input().split()))

A_list_min = sorted(A_list)
F_list_max = sorted(F_list, reverse=True)

first_OK = 10**12

def is_ok(arg):
    check_cnt = 0
    return_flag = 0
    for i in range(N):
        a_temp = A_list_min[i]
        while a_temp*F_list_max[i] > arg:
            check_cnt += 1
            a_temp -= 1
    if check_cnt <= K:
        return_flag = 1
    else:
        return_flag = 0
    return return_flag

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

print(bisect(-1, first_OK))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
hito=list(map(int,input().split()))
meshi=list(map(int,input().split()))

hito.sort()
meshi.sort(reverse=True)

S_hito=sum(hito)

def check(x):
    kari=0
    for i in range(N):
        kari+=min(hito[i],x//meshi[i])
    if S_hito<=kari+K:
        return True
    else:
        return False

l=-1
r=10**13
while l+1<r:
    mid=(l+r)//2
    if check(mid):
        r=mid
    else:
        l=mid
print(r)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()

#print('A:', A)
#print('F:', F)


res = K

lot = [A[k]*F[k] for k in range(N)]
#print(lot)
#print(res)

now = []
for k in range(N):
  now.append((-lot[k], k))
from heapq import heapify, heappop, heappush
from math import ceil
heapify(now)
#print(now)
f = heappop(now)
while res>0:
  #print(res)
  #print(now)
  s = heappop(now)
  big = lot[f[1]]
  small = lot[s[1]]
  cnt = ceil((big-small)/F[f[1]])
  if big == small:
    cnt = 1
  if cnt > A[f[1]]:
    print(lot[f[1]] - A[f[1]]*F[f[1]])
    exit()
  if cnt >= res:
    lot[f[1]] -= res*F[f[1]]
    break
  else:
    lot[f[1]] -= cnt*F[f[1]]
    A[f[1]] -= cnt
    res -= cnt
    heappush(now, (-lot[f[1]], f[1]))
  f = s
  
print(max(lot))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
from math import gcd
def lcm(x, y):
  return (x*y)//gcd(x, y)

f_lcm = 1
for k in range(N):
  f_lcm = lcm(f_lcm, F[k])

portion = [f_lcm//F[k] for k in range(N)]


#print('A:', A)
#print('F:', F)
#print('portion:', portion)
lot = [0 for _ in range(N)]


sa = sum(A) - K
sp = sum(portion)
for k in range(N):
  point = sa*portion[k]//sp
  if point > A[k]:
    lot[k] += A[k]*F[k]
    A[k] = 0
  else:
    lot[k] += point *F[k]
    A[k] -= point
res = sum(A) - K
#print(lot)
#print(A)
#print(res)

foo = []
for k in range(N):
  if A[k] == 0:
    continue
  else:
    foo.append((lot[k]+F[k], A[k], k))

from heapq import heapify, heappop, heappush
heapify(foo)
while res>0:
  res -= 1
  item = heappop(foo)
  lot[item[2]] = item[0]
  if item[1] == 1:
    continue
  else:
    heappush(foo, (item[0]+F[item[2]], item[1]-1, item[2]))
  #print(foo)
print(max(lot))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
from math import gcd
def lcm(x, y):
  return (x*y)//gcd(x, y)

f_lcm = 1
for k in range(N):
  f_lcm = lcm(f_lcm, F[k])

portion = [f_lcm//F[k] for k in range(N)]
sp = sum(portion)

#print('A:', A)
#print('F:', F)
#print('portion:', portion)
lot = [0 for _ in range(N)]


sa = sum(A) - K
for k in range(N):
  point = sa*portion[k]//sp
  if A[k] == 0:
    continue
  elif point > A[k]:
    lot[k] += A[k]*F[k]
    A[k] = 0
  else:
    lot[k] += point *F[k]
    A[k] -= point
res = sum(A) - K
#print(lot)
#print(A)
#print(res)

while res>0:
  second  = float('inf')
  for k in range(N):
    if A[k] > 0:
      second = min(second, lot[k] + F[k])
  for k in range(N):
    if A[k] > 0:
      if second == lot[k] + F[k]:
        lot[k] += F[k]
        A[k] -= 1
        res -= 1
  if res <0:
    break
  sa = sum(A) - K
  for k in range(N):
    point = sa*portion[k]//sp
    if A[k] == 0:
      continue
    elif point > A[k]:
      lot[k] += A[k]*F[k]
      A[k] = 0
    else:
      lot[k] += point *F[k]
      A[k] -= point
  res = sum(A) - K

print(max(lot))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
from math import gcd
def lcm(x, y):
  return (x*y)//gcd(x, y)

f_lcm = 1
for k in range(N):
  f_lcm = lcm(f_lcm, F[k])

portion = [f_lcm//F[k] for k in range(N)]


#print('A:', A)
#print('F:', F)
#print('portion:', portion)
lot = [0 for _ in range(N)]


sa = sum(A) - K
sp = sum(portion)
for k in range(N):
  point = sa*portion[k]//sp
  if point > A[k]:
    lot[k] += A[k]*F[k]
    A[k] = 0
  else:
    lot[k] += point *F[k]
    A[k] -= point
res = sum(A) - K
#print(lot)
#print(A)
#print(res)

while res>0:
  second  = float('inf')
  for k in range(N):
    if A[k] > 0:
      second = min(second, lot[k] + F[k])
  for k in range(N):
    if A[k] > 0:
      if second == lot[k] + F[k]:
        lot[k] += F[k]
        A[k] -= 1
        res -= 1

print(max(lot))

Submission status: Time Limit Exceeded

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)


def is_lessthanK(X):
  ans=0
  for i in range(n):
    if a[i]*f[i]>X:
      ans+=a[i]-X//f[i]
    if ans > k:
      return False
  return True


ng=-1
ok=a[-1]*f[0]
while ok-ng>1:
  mid=(ok+ng)//2
  if is_lessthanK(mid):
    ok=mid
  else:
    ng=mid
print(ok)

Submission status: Time Limit Exceeded

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)


def is_lessthanK(X):
  ans=0
  for i in range(n):
    ans+=max(0,a[i]-X//f[i])
    if ans > k:
      return False
  return True


ng=-1
ok=10**13
while ok-ng>1:
  mid=(ok+ng)//2
  if is_lessthanK(mid):
    ok=mid
  else:
    ng=mid
print(ok)

Submission status: Time Limit Exceeded

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)

def is_lessthanK(X):
  ans=0
  for i in range(n):
    ans+=max(0,a[i]-X//f[i])
  return ans<=k

ng=-1
ok=10**13
while ok-ng>1:
  mid=(ok+ng)//2
  if is_lessthanK(mid):
    ok=mid
  else:
    ng=mid
print(ok)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')

    @cc.export('is_ok', '(i8[:],i8[:],i8,i8)')
    def is_ok(A, F, x, k):
        tmp = 0
        for a, f in zip(A, F):
            while a * f > x:
                a -= 1
                tmp += 1
        return tmp <= k

    cc.compile()
    exit(0)

from my_module import is_ok
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)
F = np.sort(F)[::-1]

ok = 10 ** 16
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(A, F, mid, k):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Time Limit Exceeded

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 is_ok(x):
    tmp = 0
    for a, f in zip(A, F):
        while a * f > x:
            a -= 1
            tmp += 1
    return tmp <= k


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

print(ok)

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    # 達成スコアを決める
    # 修行回数がK以下を達成できるスコアを二分探索
    def check(X):
        cnt = 0
        for i in range(N):
            a = X // F[i]
            if a < A[i]:  # 修行をしてスコアを最小化する
                cnt += A[i] - a
        return cnt <= K

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

    ok = 10 ** 12 # 最大スコア a: 10**6 * x:10**6
    ng = -1
    while ok - ng > 1:
        X = (ok + ng) // 2
        if check(X):
            ok = X
        else:
            ng = X

    print(ok)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    # 達成スコアを決める
    # 修行回数がK以下を達成できるスコアを二分探索
    def check(X):
        cnt = 0
        for i in range(N):
            a = X // F[i]
            if a < A[i]:  # 修行をしてスコアを最小化する
                cnt += A[i] - a
        return cnt <= K

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

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

    print(ok)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)
af = [a[i]*f[i] for i in range(n)]

def check(x):
  r = 0
  for i in range(n):
    r += (max(0,(af[i]-x))+f[i]-1)//f[i]
  #print(r, x)
  if r<=k:
    return True
  else:
    return False
ok = 10**12+1
ng = -1
while ok-ng>1:
  mid = (ok + ng)//2
  if check(mid):
    ok = mid
  else:
    ng = mid
print(ok)

Submission status: Time Limit Exceeded

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

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

ng = -1
ok = 0
for i in range(N):
  ok = max(A[i]*F[i], ok)

def is_ok(arg):
  cnt = 0
  for i in range(N):
    cnt += max(A[i] - arg//F[i], 0)
  return cnt <= K

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

print(m_bisect(ng, ok))

Submission status: Time Limit Exceeded

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

ng = -1
ok = 0
for i in range(N):
  ok = max(A[i]*F[i], ok)

def is_ok(arg):
  cnt = 0
  for i in range(N):
    cnt += max(A[i] - arg//F[i], 0)
  return cnt <= K

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

print(m_bisect(ng, ok))

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
F = sorted([int(i) for i in input().split()])
OK = 10**12
NG = -1

while OK-NG > 1:
    mid = (OK+NG)//2
    cnt = 0
    for a, f in zip(A, F):
        if a*f > mid:
            cnt += math.ceil((a*f-mid)/f)
    if cnt <= K:
        OK = mid
    else:
        NG = mid
print(OK)

Submission status: Time Limit Exceeded

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

hq = []
heapq.heapify(hq)  # リストhqのheap化
for a, f in zip(A, F):
    heapq.heappush(hq, (-a*f, a, f))  # heap化されたリストhqに要素xを追加

for _ in range(K):
    _, a, f = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    a -= 1
    heapq.heappush(hq, (-a*f, a, f))  # heap化されたリストhqに要素xを追加

print(max(0, -min(hq)[0]))

Submission status: Time Limit Exceeded

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

def is_ok(arg):
    cnt=0
    for i in range(n):
        cnt+=max(a[i]-arg//f[i], 0)
    return cnt<=k

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

print(meguru_bisect(-1, 10**12))

Submission status: Time Limit Exceeded

Solution code:
import math
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]

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

af = [[a[i]*f[i], a[i], f[i]] for i in range(n)]
af.sort(reverse=True)

def check(mid):
    count = 0
    for i in range(n):
        num = math.ceil((af[i][0] - mid) / af[i][2])
        if num > af[i][1]:
            return False
        else:
            count += num
            if count > k:
                return False
    else:
        return True

# https://qiita.com/hamko/items/794a92c456164dcc04ad
def binary_search():
    ng = -1 # left:絶対に達成不可能なもの
    ok = 10**13 # right:絶対に達成可能なもの
    while (ok - ng > 1):
        mid = (ng + ok) // 2
        if check(mid) == True:
            ok = mid
        else:
            ng = mid
    return ok
print(binary_search())

Submission status: Time Limit Exceeded

Solution code:
def is_good(mid, key):
    ret = 0
    for i in range(N):
        ret += max(0, A[i] - mid // F[i])
    return ret <= key


def binary_search(key):
    bad, good = -1, 10 ** 18
    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 = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)
print(binary_search(K))

Submission status: Time Limit Exceeded

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 is_ok(m):
    c = 0
    for a,f in zip(A,F):
        d = m//f
        c += max(0, a-d)
        if c > K:
            return False
    return True

ok = 10**13
ng = -1
while ok-ng > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
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)

left=0
right=10**12+1
ans=float("INF")
while True:
    mid=(left+right)//2

    now=0
    for i in range(N):
        if F[i]*A[i]>mid:
            now+=ceil(((F[i]*A[i])-mid)/F[i])
    #print(now, mid)
    if now==K:
        ans=min(ans, mid)
        right=mid
    elif now>K:
        if left==mid:
            break
        left=mid
    else:
        if right==mid:
            break
        right=mid
        ans=min(ans, mid)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def binary_search(K, A, F):
    ng = -1
    ok = 10 ** 18
    while ok - ng > 1:
        mid = (ok + ng) // 2
        need_k = sum(max(0, a - mid // f) for a, f in zip(A, F))
        if need_k <= K:
            ok = mid
        else:
            ng = mid
    return ok


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

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

    ans = binary_search(K, A, F)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,K=map(int,input().split())
A=np.array(input().split(),dtype=int)
F=np.array(input().split(),dtype=int)

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


for i in range(10**12,0,-1):
    b=A-i//F
    b=np.where(b<0,0,b)
    if K<np.sum(b):
        ans=i+1
        break
    ans=0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,K=map(int,input().split())
A=np.array(input().split(),dtype=int)
F=np.array(input().split(),dtype=int)

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

X=A*F

for i in range(np.max(X),0,-1):
    b=A-i//F
    b=np.where(b<0,0,b)
    if K<np.sum(b):
        ans=i+1
        break
    ans=0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
A = sorted(list(map(int,input().split())))
F = sorted(list(map(int,input().split())))[::-1]
o = []
for a,f in zip(A,F):
    o.append(a*f)
ok = max(o)    
ng = -1

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

Submission status: Time Limit Exceeded

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


def can_eat(t):
    F_time = sorted([t // f for f in F])
    training = 0
    for i in range(N):
        training += max(0, A[i] - F_time[i])
    return training <= K


# bisect
l, r = -1, 10 ** 12
while r - l > 1:
    m = (r + l) // 2
    if can_eat(m):
        r = m
    else:
        l = m
print(r)

Submission status: Time Limit Exceeded

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

A.sort(reverse=True)
F.sort()
wk = 0
for i in range(N):
  wk += A[i] * F[i]
#print(wk)

def is_ok(arg):
  # 条件を満たすかどうか？問題ごとに定義
  cnt = 0
  for i in range(N):
    a,f = A[i], F[i]   
    if a*f <= arg:
      continue
    else:
      #(a-k) * f <= arg
      # a - arg/f <= k
      cnt += ceil(a-arg/f)
  return cnt <= K

def meguru_bisect(ng, ok):
  '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

ng = -1
ok = 10**12 + 10
ans = meguru_bisect(ng,ok)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

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

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

def check(x):
  k = 0
  for a,f in zip(A, F):
    if a*f > x:
      while a > 0:
        a -= 1
        k += 1
        if a*f <= x: break

  return k <= K

# AをX以下にできるか？?
ng,ok = 0, 10**18+1
while ok-ng > 1:
  x = (ok+ng)//2
  if check(x):
    ok = x
  else:
    ng = x

print(ok)

Submission status: Time Limit Exceeded

Solution code:
from heapq import *
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
F = list(map(int, input().split()))
F.sort(reverse=True)
data = []
for a, f in zip(A, F):
    heappush(data, (-a*f, a, f))
for _ in range(K):
    x, a, f = heappop(data)
    if a > 0:
        a -= 1
    heappush(data, (-a*f, a, f))

print(-heappop(data)[0])

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    worst_score = 10 ** 12

    n, k = ns()
    a = na()
    f = na()
    a.sort()
    f.sort(reverse=True)
    score = [ai * fi for ai, fi in zip(a, f)]

    l = -1
    r = worst_score + 1

    while r - l > 1:
        middle = (l + r) // 2
        tmp_k = k
        for i in range(n):
            tmp = math.ceil((score[i] - middle) / f[i])
            tmp_k -= max(0, tmp)

            if tmp_k < 0:
                break

        if tmp_k >= 0:
            r = middle
        else:
            l = middle
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    low = -1
    up = 10**12
    while up - low > 1:
        v = (up + low) // 2
        tk = K
        for i in range(N):
            tk -= max(0, A[i] - (v // F[i]))
            if tk < 0: break
        if tk < 0:
            low = v
        else:
            up = v
    print(up)

if __name__ == '__main__':
    abc144_e()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())), reverse=True)
    F = sorted(list(map(int, input().split())))
    q = []
    for i in range(N):
        q.append((-A[i]*F[i], A[i], F[i]))
    import heapq
    heapq.heapify(q)
    for i in range(K):
        time, a, f = heapq.heappop(q)
        # print("###########")
        # print(time, a, f)
        if a <= 0:
            print(0)
            return
        heapq.heappush(q, (-(a-1)*f, a-1, f))
        # print(-(a-1)*f, a-1, f)
    time, _, __ = heapq.heappop(q)
    print(-time)

    
if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, K = NMI()
    A = NLI()
    F = NLI()
    A.sort()
    F.sort(reverse=True)
    ok = 10**13
    ng = 0
    for i in range(50):
        mid = (ok+ng) // 2
        limits = [mid//f for f in F]
        ks = [max(a-l, 0) for a, l in zip(A, limits)]
        if sum(ks) <= K:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, K = NMI()
    A = NLI()
    F = NLI()
    A.sort()
    ok = 10**13
    ng = 0
    for i in range(100):
        mid = (ok+ng) // 2
        limits = [mid//f for f in F]
        limits.sort()
        ks = [max(a-l, 0) for a, l in zip(A, limits)]
        if sum(ks) <= K:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#OK牧場
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
#こっちは変えられない
f=sorted(list(map(int,input().split())),reverse=True)
l,r=0,10**12
def cal(x):
    global n,f,a,k
    ret=0
    for i in range(n):
        ret+=max(0,a[i]-(x//f[i]))
    #print(ret,x)
    return ret
while l+1<r:
    x=l+(r-l)//2
    if cal(x)<=k:
        r=x
    else:
        l=x
if cal(l)<=k:
    print(l)
else:
    print(r)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ok = 10**12
ng = -1


def check(time):
    shugyou = 0
    for i in range(N):
        if A[i]*F[i] > time:
            shugyou += A[i] - (time//F[i])
    return shugyou <= K


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

Submission status: Time Limit Exceeded

Solution code:
# いきぬきreview　忘れた問題
# gluttony
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
F.sort()
A.sort(reverse=True)


def func(X):
    s = 0
    for i in range(N):
        a, f = A[i], F[i]
        s += max(0, a-X//f)
    return s <= K


R = 10**12
L = -1
while R-L > 1:
    m = (R+L)//2
    if func(m):
        R = m
    else:
        L = m
print(R)

Submission status: Time Limit Exceeded

Solution code:
import copy
from heapq import heappop, heapify, heappush
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]
ans = 0
A.sort(reverse=True)
F.sort()
s = []
for i in range(N):
    s.append([A[i]*F[i], A[i], F[i]])
s.sort(reverse=True, key=lambda x: x[0])

def f(l, T):
    cur = 0
    num = 0
    S = copy.deepcopy(l)
    while cur <= K:
        if num == N:
            break
        a, b, c = S[num]
        if a <= T:
            break
        cur += math.ceil((a - T)/c)
        num += 1
    if cur <= K:
        return True
    else:
        return False

ok, ng = s[0][0], -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if f(s, mid) == True:
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Time Limit Exceeded

Solution code:
import copy
from heapq import heappop, heapify, heappush
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]
ans = 0
A.sort(reverse=True)
F.sort()
s = []
for i in range(N):
    s.append((-A[i]*F[i], A[i], F[i]))
heapify(s)

def f(l, T):
    cur = 0
    S = copy.deepcopy(l)
    while cur <= K:
        if len(S) == 0:
            break
        a, b, c = heappop(S)
        a = -a
        if a <= T:
            break
        cur += math.ceil((a - T)/c)
    if cur <= K:
        return True
    else:
        return False

ok, ng = -s[0][0], -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if f(s, mid) == True:
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Time Limit Exceeded

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

asum = sum(a)

def test(x):
    t = [min(a[i], x//f[i]) for i in range(n)]
    return asum - sum(t)


ng = -1
ok = 10**13
while abs(ok-ng)>1:
    mid = (ok+ng)//2
    if test(mid) <= k:
        ok = mid
    else:
        ng = mid

print(ok)