Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
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)

    B=[]
    for i in range(N):
        B.append((A[i]*F[i],F[i]))

    B.sort()
    for _ in range(K):
        if not len(B) > 0:
            break
        b,f = B.pop()
        front = (b-f,f)

        if b-f > 0:
            bisect.insort(B,front)

    print(max(B)[0] if len(B) > 0 else 0)
    # print(B)



if __name__ == "__main__":
  main()

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
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)

    def c(s): # sに対して単調減少
        sum_x = 0
        for i in range(N):
            a,f=A[i],F[i]
            tp = s//f
            if not a <= tp:
                sum_x += a-tp

        return sum_x <= K

    l=-1
    r=10**20
    while r-l>1:
        mid = (l+r)//2
        if c(mid):
            r = mid
        else:
            l = mid

    print(r)

if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
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)

    B=[]
    for i in range(N):
        B.append((A[i]*F[i],F[i]))

    B.sort()
    for _ in range(K):
        if not len(B) > 0:
            break
        b,f = B.pop()
        front = (b-f,f)

        if b-f > 0:
            bisect.insort(B,front)

    print(max(B)[0] if len(B) > 0 else 0)
    # print(B)



if __name__ == "__main__":
  main()

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
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)

    def c(s): # sに対して単調減少
        sum_x = 0
        for i in range(N):
            a,f=A[i],F[i]
            tp = s//f
            if not a <= tp:
                sum_x += a-tp

        return sum_x <= K

    l=-1
    r=10**20
    while r-l>1:
        mid = (l+r)//2
        if c(mid):
            r = mid
        else:
            l = mid

    print(r)

if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
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)

    B=[]
    for i in range(N):
        B.append((A[i]*F[i],F[i]))

    B.sort(reverse=True)
    k = K
    # print(B)
    while k > 0:
        i = 0
        while i < len(B) and B[i][0] == 0:
            i += 1
        if not i < len(B):
            break
        B[i] = (B[i][0]-B[i][1],B[i][1])
        k -= 1
        B.sort(reverse=True)

    print(max(B)[0])
    # print(B)



if __name__ == "__main__":
  main()


Fixed submission:
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
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)

    def c(s): # sに対して単調減少
        sum_x = 0
        for i in range(N):
            a,f=A[i],F[i]
            tp = s//f
            if not a <= tp:
                sum_x += a-tp

        return sum_x <= K

    l=-1
    r=10**20
    while r-l>1:
        mid = (l+r)//2
        if c(mid):
            r = mid
        else:
            l = mid

    print(r)

if __name__ == "__main__":
  main()