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

input = sys.stdin.readline


class AtCoder:
    def __lt__(self, other):
        return self[0] < other[0]

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

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

        hq = []
        heapq.heapify(hq)
        for i in range(N):
            heapq.heappush(hq, (-1 * A[i] * F[i], (F[i], A[i])))

        while K > 0:
            score = heapq.heappop(hq)
            if score[1][1] == 0:
                print(0)
                exit()
            else:
                if score[1][1] - F[0] > 0:
                    K -= score[1][1] - F[0]
                    new_A = F[0]
                else:
                    K -= 1
                    new_A = score[1][1] - 1
                heapq.heappush(hq, (-1 * new_A * score[1][0], (score[1][0], new_A)))

        print(-1 * heapq.heappop(hq)[0])


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import sys

input = sys.stdin.readline


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

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

        l, r = -1, 10 ** 12
        while l + 1 < r:
            mid = (l + r) // 2

            s = 0
            for i in range(N):
                s += max(0, A[i] - mid // F[i])
            if s <= K:
                r = mid
            else:
                l = mid
        print(r)


# Run main
if __name__ == '__main__':
    AtCoder().main()

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

input = sys.stdin.readline


class AtCoder:
    def __lt__(self, other):
        return self[0] < other[0]

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

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

        hq = []
        heapq.heapify(hq)
        for i in range(N):
            heapq.heappush(hq, (-1 * A[i] * F[i], (F[i], A[i])))

        while K > 0:
            score = heapq.heappop(hq)
            if score[1][1] == 0:
                print(0)
                exit()
            else:
                K -= 1
                new_A = score[1][1] - 1
                heapq.heappush(hq, (-1 * new_A * score[1][0], (score[1][0], new_A)))

        print(-1 * heapq.heappop(hq)[0])


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import sys

input = sys.stdin.readline


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

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

        l, r = -1, 10 ** 12
        while l + 1 < r:
            mid = (l + r) // 2

            s = 0
            for i in range(N):
                s += max(0, A[i] - mid // F[i])
            if s <= K:
                r = mid
            else:
                l = mid
        print(r)


# Run main
if __name__ == '__main__':
    AtCoder().main()