Using 2 heaps. Runtime top 90%  Memory top 80%
Approach\nThe solution uses two heaps: a max heap for buy orders and a min heap for sell orders, making it easy to get the highest buy price and the lowest sell
# Approach\nThe solution uses two heaps: a max heap for buy orders and a min heap for sell orders, making it easy to get the highest buy price and the lowest sell price quickly. As we go through each order, we add it to the right heap based on whether it\'s a buy or sell order. We then check if any buy and sell orders can match, adjusting their amounts and removing them if they\'re fully matched. Once all orders are processed, we count up the amounts of the remaining unmatched orders in both heaps.\n\n# Complexity\n- Time complexity: O(NlogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nstruct order_t{\n    int price;\n    int amount;\n    order_t(int p, int a): price(p), amount(a) {};\n\n    std::strong_ordering operator<=>(const order_t& other) const {\n        return price <=> other.price;  // Compare only the \'price\' field\n    }\n};\n\nclass Solution {\npublic:\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        std::vector<order_t> buy_heap; // max heap\n        std::vector<order_t> sell_heap; // min heap\n        for(const auto& order : orders) {\n            if(order.at(2) == 0) {\n                buy_heap.emplace_back(order.at(0), order.at(1));\n                std::push_heap(buy_heap.begin(), buy_heap.end());\n            } else {\n                sell_heap.emplace_back(order.at(0), order.at(1));\n                std::push_heap(sell_heap.begin(), sell_heap.end(), std::greater<>{});\n            }\n\n            // remove orders from backlog\n            while(not(buy_heap.empty() or sell_heap.empty()) and buy_heap.front() >= sell_heap.front()){\n                int amount = std::min(buy_heap.front().amount, sell_heap.front().amount);\n                \n                buy_heap[0].amount -= amount;\n                sell_heap[0].amount -= amount;\n                \n                if(buy_heap[0].amount == 0){\n                    std::pop_heap(buy_heap.begin(),buy_heap.end());\n                    buy_heap.pop_back();\n                }\n                if(sell_heap[0].amount == 0) {\n                    std::pop_heap(sell_heap.begin(),sell_heap.end(), std::greater<>{});\n                    sell_heap.pop_back();\n                }\n            }\n        }\n        int count_backlog = 0;\n        for(const auto& order : buy_heap){\n            count_backlog += order.amount%1000000007;\n            count_backlog %= 1000000007;\n        }\n        for(const auto& order : sell_heap){\n            count_backlog += order.amount%1000000007;\n            count_backlog %= 1000000007;\n        }\n\n        return count_backlog;\n    }\n};\n```
['C++']