Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

if N == 1:
    a = A[0]
    f = F[0]
    ans = max(a - K, 0) * f
    print(ans)
    exit()

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

heap = []
for a, f in zip(A, F):
    heap.append((-a * f, a, f))
heapq.heapify(heap)

while K > 0:
    _, a, f = heapq.heappop(heap)
    if a == 0:
        break
    af2 = -heap[0][0]
    next_a = max(0, math.ceil(af2 / f) - 1)
    k = min(K, a - next_a)
    K -= k
    a -= k
    heapq.heappush(heap, (-a * f, a, f))

ans = 0
for af, _, _ in heap:
    ans = max(ans, -af)
print(ans)


Fixed submission:
import heapq
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

if N == 1:
    a = A[0]
    f = F[0]
    ans = max(a - K, 0) * f
    print(ans)
    exit()

A = np.array(A, dtype=int)
F = np.array(F, dtype=int)
A.sort()
F.sort()
F = F[::-1]


def required_k(score):
    # score を出すために必要な K
    return np.ceil(np.maximum(A - score / F, 0)).sum()


ok = (A * F).max()
ng = -1
while abs(ok - ng) > 1:
    score = (ok + ng) // 2
    if required_k(score) <= K:
        ok = score
    else:
        ng = score
print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

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

heap = []
for a, f in zip(A, F):
    heap.append((-a * f, a, f))
heapq.heapify(heap)
for _ in range(K):
    _, a, f = heap[0]
    if a == 0:
        break
    a -= 1
    heapq.heapreplace(heap, (-a * f, a, f))

ans = 0
for af, _, _ in heap:
    ans = max(ans, -af)
print(ans)


Fixed submission:
import heapq
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

if N == 1:
    a = A[0]
    f = F[0]
    ans = max(a - K, 0) * f
    print(ans)
    exit()

A = np.array(A, dtype=int)
F = np.array(F, dtype=int)
A.sort()
F.sort()
F = F[::-1]


def required_k(score):
    # score を出すために必要な K
    return np.ceil(np.maximum(A - score / F, 0)).sum()


ok = (A * F).max()
ng = -1
while abs(ok - ng) > 1:
    score = (ok + ng) // 2
    if required_k(score) <= K:
        ok = score
    else:
        ng = score
print(ok)