Min and max Heap
\tclass Solution(object):\n\t\tdef getNumberOfBacklogOrders(self, orders):\n\t\t\t"""\n\t\t\t:type orders: List[List[int]]\n\t\t\t:rtype: int\n\t\t\t"""\n\t\t\t
\tclass Solution(object):\n\t\tdef getNumberOfBacklogOrders(self, orders):\n\t\t\t"""\n\t\t\t:type orders: List[List[int]]\n\t\t\t:rtype: int\n\t\t\t"""\n\t\t\tbuy = []\n\t\t\tsell = []\n\t\t\tfor i in range(len(orders)):\n\t\t\t\torder = orders[i]\n\t\t\t\tif order[2] == 0:\n\t\t\t\t\twhile sell and sell[0][0] <= order[0] and order[1] > 0:\n\t\t\t\t\t\tnode = heapq.heappop(sell)\n\t\t\t\t\t\tif node[1] >= order[1]:\n\t\t\t\t\t\t\tnode[1] -= order[1]\n\t\t\t\t\t\t\torder[1] = 0\n\t\t\t\t\t\t\theapq.heappush(sell, ([node[0], node[1]]))\n\t\t\t\t\t\telse:\n\t\t\t\t\t\t\torder[1] -= node[1]\n\t\t\t\t\tif order[1] > 0:\n\t\t\t\t\t\theapq.heappush(buy, ([-order[0], order[1]]))\n\t\t\t\telse:\n\t\t\t\t\twhile buy and abs(buy[0][0]) >= order[0] and order[1] > 0:\n\t\t\t\t\t\tnode = heapq.heappop(buy)\n\t\t\t\t\t\tif node[1] >= order[1]:\n\t\t\t\t\t\t\tnode[1] -= order[1]\n\t\t\t\t\t\t\torder[1] = 0\n\t\t\t\t\t\t\theapq.heappush(buy, ([node[0], node[1]]))\n\t\t\t\t\t\telse:\n\t\t\t\t\t\t\torder[1] -= node[1]\n\t\t\t\t\tif order[1] > 0:\n\t\t\t\t\t\theapq.heappush(sell, ([order[0], order[1]]))\n\t\t\tres = 0\n\t\t\tfor a, b in buy:\n\t\t\t\tres += b\n\t\t\tfor a, b in sell:\n\t\t\t\tres += b\n\t\t\treturn res % (10**9 + 7)
[]