python min + max heap
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)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n\n\n        buy_backlog = []\n        sell_backlog = []\n\n\n        for i in range(len(orders)):\n            p, n, t = orders[i]\n            if not t:\n                while sell_backlog and sell_backlog[0][0] <= p and n:\n                     if sell_backlog[0][1] <= n:\n                        n -= sell_backlog[0][1]\n                        heapq.heappop(sell_backlog)\n                     else:\n\n                        sell_backlog[0][1] -=n\n                        n = 0\n                if n:\n                    heapq.heappush(buy_backlog, [-p, n])\n            else:\n                while buy_backlog and -buy_backlog[0][0] >= p and n:\n                     if buy_backlog[0][1] <= n:\n                        n -= buy_backlog[0][1]\n                        heapq.heappop(buy_backlog)\n                     else:\n\n                        buy_backlog[0][1] -=n\n                        n = 0\n                if n:\n                    heapq.heappush(sell_backlog, [p, n])\n\n        \n        return (sum(map(lambda x:x[1], sell_backlog)) + sum(map(lambda x:x[1], buy_backlog))) % (10**9 + 7)\n\n\n\n\n\n\n\n\n```
['Heap (Priority Queue)', 'Python3']