Buggy python submission (verdict: Time Limit Exceeded):
def check(limit, max_training, costs, volumes):
    from math import floor
    remain_training = max_training
    for id, (cost, volume) in enumerate(zip(costs, volumes)):
        if cost * volume <= limit:
            continue
        else:
            lowest_cost = floor(limit / volume)
            remain_training -= (cost - lowest_cost)
        if remain_training < 0:
            return False
    return True


def main():
    n, k = map(int, input().rstrip("\n").split(" "))
    costs = list(map(int, input().rstrip("\n").split(" ")))
    volumes = list(map(int, input().rstrip("\n").split(" ")))

    costs.sort()
    volumes.sort(reverse=True)
    queue = []
    total_cost = 0

    success = False

    max_cost = max([cost * volume for cost, volume in zip(costs, volumes)])
    min_cost = 0

    while (min_cost + 1) < max_cost:
        center_cost = (min_cost + max_cost) // 2
        success = check(center_cost, k, costs, volumes)
        if success:
            max_cost = center_cost
        else:
            min_cost = center_cost
    if check(min_cost, k, costs, volumes):
        print(min_cost)
    else:
        print(max_cost)


if __name__ == '__main__':
    main()

Fixed submission:
def check(limit, max_training, costs, volumes):
    from math import floor
    remain_training = max_training
    for id, (cost, volume) in enumerate(zip(costs, volumes)):
        if cost * volume <= limit:
            continue
        else:
            lowest_cost = floor(limit / volume)
            remain_training -= (cost - lowest_cost)
        if remain_training < 0:
            return False
    return True


def main():
    n, k = map(int, input().rstrip("\n").split(" "))
    costs = list(map(int, input().rstrip("\n").split(" ")))
    volumes = list(map(int, input().rstrip("\n").split(" ")))

    costs.sort()
    volumes.sort(reverse=True)
    queue = []
    total_cost = 0

    success = False

    max_cost = max([cost * volume for cost, volume in zip(costs, volumes)])
    min_cost = 0

    while (min_cost + 1) < max_cost:
        center_cost = (min_cost + max_cost) // 2
        success = check(center_cost, k, costs, volumes)
        if success:
            max_cost = center_cost
        else:
            min_cost = center_cost
    if check(min_cost, k, costs, volumes):
        print(min_cost)
    else:
        print(max_cost)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().rstrip("\n").split(" "))
    costs = list(map(int, input().rstrip("\n").split(" ")))
    volumes = list(map(int, input().rstrip("\n").split(" ")))
    
    costs.sort()
    volumes.sort(reverse=True)
    from heapq import heappush, heappop
    queue = []
    total_cost = 0
    for id, (cost, volume) in enumerate(zip(costs, volumes)):
        total_cost += cost
        heappush(queue, (cost * volume * -1,id, cost, volume))
    for i in range(min(total_cost, k)):
        
        duration, id, cost, volume = heappop(queue)
        cost -= 1
        if cost > 0:
            heappush(queue, (cost * volume * -1, id, cost, volume) )
        
        if not queue:
            break
    if queue:
        result = min([duration for duration, id, cost, volume in queue])
        print(result * -1)
    else:
        print(0)
    

if __name__ == '__main__':
  main()



Fixed submission:
def check(limit, max_training, costs, volumes):
    from math import floor
    remain_training = max_training
    for id, (cost, volume) in enumerate(zip(costs, volumes)):
        if cost * volume <= limit:
            continue
        else:
            lowest_cost = floor(limit / volume)
            remain_training -= (cost - lowest_cost)
        if remain_training < 0:
            return False
    return True


def main():
    n, k = map(int, input().rstrip("\n").split(" "))
    costs = list(map(int, input().rstrip("\n").split(" ")))
    volumes = list(map(int, input().rstrip("\n").split(" ")))

    costs.sort()
    volumes.sort(reverse=True)
    queue = []
    total_cost = 0

    success = False

    max_cost = max([cost * volume for cost, volume in zip(costs, volumes)])
    min_cost = 0

    while (min_cost + 1) < max_cost:
        center_cost = (min_cost + max_cost) // 2
        success = check(center_cost, k, costs, volumes)
        if success:
            max_cost = center_cost
        else:
            min_cost = center_cost
    if check(min_cost, k, costs, volumes):
        print(min_cost)
    else:
        print(max_cost)


if __name__ == '__main__':
    main()