C++ 2 Heaps
A practical problem on how to process level 2 quotes. It took me a while to implement during the contest.\n\nWe can use min (for sell) and max (for buy) heaps. 
A practical problem on how to process [level 2 quotes](https://stockstotrade.com/understanding-level-2-quotes-infographic/). It took me a while to implement during the contest.\n\nWe can use min (for sell) and max (for buy) heaps.  Note that we do not process an order right away, but just put it into one of the heaps. Then, we just fulfill orders while we can, pulling them from the heads of our heaps.\n\nThe intuition here is that, if there are existing orders in the heaps, those are orders that we could not process before.\n\n**C++**\nNote that we are pushing negative prices to `sell` to turn in from max heap to min heap.\n\n```cpp\nint getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n    priority_queue<array<int, 2>> buy, sell;\n    long res = 0;\n    for (auto &o : orders) {\n        res += o[1];\n        if (o[2])\n            sell.push({-o[0], o[1]});\n        else\n            buy.push({o[0], o[1]});\n        while (!sell.empty() && !buy.empty() && -sell.top()[0] <= buy.top()[0]) {\n            auto [sell_p, sell_a] = sell.top(); sell.pop();\n            auto [buy_p, buy_a] = buy.top(); buy.pop();\n            auto execute = min(sell_a, buy_a);\n            res -= 2 * execute;\n            if (sell_a > execute)\n                sell.push({sell_p, sell_a - execute});\n            if (buy_a > execute)\n                buy.push({buy_p, buy_a - execute});   \n        }\n    }\n    return res % 1000000007;\n}\n```
[]