Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = sum([max(0, a[i] - mid // f[i]) for i in range(n)])
    if ck <= k: right = mid
    else: left = mid

print(right)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k: right = mid
    else: left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline

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)
    q = [None] * n
    for i in range(n):
        q[i] = (-a[i]*f[i], -f[i])
    heapify(q)

    for i in range(k):
        t, g = heappop(q)
        heappush(q, (t-g, g))

    ans, _ = heappop(q)
    print(-ans)

if __name__ == "__main__":
    main()


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k: right = mid
    else: left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline

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)

    q = [(-a[i]*f[i], -f[i]) for i in range(n)]
    heapify(q)

    for i in range(k):
        t, g = heappop(q)
        heappush(q, (t-g, g))

    ans, _ = heappop(q)
    print(-ans)

if __name__ == "__main__":
    main()


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k: right = mid
    else: left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush, heapify
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

q = [(-a[i]*f[i], -f[i]) for i in range(n)]
heapify(q)

for i in range(k):
    t, g = heappop(q)
    heappush(q, (t-g, g))

ans, _ = heappop(q)
print(-ans)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k: right = mid
    else: left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush, heapify
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

q = [(-a[i]*f[i], -f[i]) for i in range(n)]
heapify(q)

for i in range(k):
    t, g = heappop(q)
    heappush(q, (t-g, g))

ans, _ = heappop(q)
print(-ans)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k: right = mid
    else: left = mid

print(right)