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

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
A = inl()
F = inl()
A.sort()
F.sort(reverse=True)


def solve():
    if N == 1:
        return max(A[0] - K, 0) * F[0]
    hp = []
    for i in range(N):
        heapq.heappush(hp, (-A[i] * F[i], F[i]))
    k = K
    while k > 0:
        t0, f0 = heapq.heappop(hp)
        if t0 == 0:
            break
        t0 = -t0
        t1, f1 = hp[0]
        t1 = -t1
        if t0 == t1:
            m = 1
        else:
            assert t0 > t1
            m = ((t0 - t1) + f0 - 1) // f0
        m = min(m, k)
        k -= m
        t0 -= m * f0
        heapq.heappush(hp, (-t0, f0))

    t0, _ = hp[0]
    return -t0


print(solve())


Fixed submission:
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
A = inl()
F = inl()
A.sort()
F.sort(reverse=True)


def check(val):
    k = K
    for i in range(N):
        tmp = A[i] * F[i]
        if tmp <= val:
            continue
        dec = ((tmp - val) + F[i] - 1) // F[i]
        assert A[i] >= dec
        assert (A[i] - dec) * F[i] <= val
        k -= dec
        if k < 0:
            return False
    return True


def solve():
    ng, ok = -1, max([A[i] * F[i] for i in range(N)])
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(solve())

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

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
A = inl()
F = inl()
A.sort()
F.sort(reverse=True)


def solve():
    if N == 1:
        return max(A[0] - K, 0) * F[0]
    hp = []
    for i in range(N):
        heapq.heappush(hp, (-A[i] * F[i], F[i]))
    k = K
    while k > 0:
        t0, f0 = heapq.heappop(hp)
        t0 = -t0
        t1, f1 = hp[0]
        t1 = -t1
        if t0 == t1:
            m = 1
        else:
            assert t0 > t1
            m = ((t0 - t1) + f0 - 1) // f0
        m = min(m, k)
        k -= m
        t0 -= m * f0
        heapq.heappush(hp, (-t0, f0))

    t0, _ = hp[0]
    return -t0


print(solve())


Fixed submission:
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
A = inl()
F = inl()
A.sort()
F.sort(reverse=True)


def check(val):
    k = K
    for i in range(N):
        tmp = A[i] * F[i]
        if tmp <= val:
            continue
        dec = ((tmp - val) + F[i] - 1) // F[i]
        assert A[i] >= dec
        assert (A[i] - dec) * F[i] <= val
        k -= dec
        if k < 0:
            return False
    return True


def solve():
    ng, ok = -1, max([A[i] * F[i] for i in range(N)])
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(solve())