two heaps implementation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n log n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```\nimport heapq\nfrom typing import List\n\nclass Solution:\n    def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n        buy = []    # Max heap (using negative prices)\n        sell = []   # Min heap\n\n        def toBuy(buyPrice: int, buyAmount: int):\n            while buyAmount > 0 and sell and sell[0][0] <= -buyPrice:\n                sellPrice, sellAmount = heapq.heappop(sell)\n                finalAmount = min(buyAmount, sellAmount)\n                sellAmount -= finalAmount\n                buyAmount -= finalAmount\n                if sellAmount > 0:\n                    heapq.heappush(sell, [sellPrice, sellAmount])\n            # Push the remaining buy order into the max heap if not fully matched\n            if buyAmount > 0:\n                heapq.heappush(buy, [buyPrice, buyAmount])\n\n        def toSell(sellPrice: int, sellAmount: int):\n            while sellAmount > 0 and buy and sellPrice <= -buy[0][0]:\n                buyPrice, buyAmount = heapq.heappop(buy)\n                finalAmount = min(sellAmount, buyAmount)\n                buyAmount -= finalAmount\n                sellAmount -= finalAmount\n                if buyAmount > 0:\n                    heapq.heappush(buy, [buyPrice, buyAmount])\n            # Push the remaining sell order into the min heap if not fully matched\n            if sellAmount > 0:\n                heapq.heappush(sell, [sellPrice, sellAmount])\n\n        for price, amount, typ in orders:\n            if typ == 0:  # Buy order\n                toBuy(-price, amount)  # Use negative price to simulate max heap\n            else:  # Sell order\n                toSell(price, amount)\n            \n        # Calculate the total remaining orders in the backlog\n        ans = sum(amount for _, amount in buy) \n        ans += sum(amount for _, amount in sell)\n        return ans % (10**9 + 7)\n\n```
['Python3']