1801. Number of Orders in the Backlog.cpp
Code\n\nclass Solution {\npublic:\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        priority_queue<pair<int, int>> buy; \n        priori
**Code**\n```\nclass Solution {\npublic:\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        priority_queue<pair<int, int>> buy; \n        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> sell; \n        for (auto& order : orders) {\n            auto price = order[0], qty = order[1], type = order[2]; \n            if (type == 0) buy.emplace(price, qty); \n            else sell.emplace(price, qty);             \n            while (size(buy) && size(sell) && buy.top().first >= sell.top().first) {\n                auto [bp, bq] = buy.top(); buy.pop(); \n                auto [sp, sq] = sell.top(); sell.pop(); \n                if (bq > sq) {\n                    bq -= sq; \n                    buy.emplace(bp, bq); \n                } else if (bq < sq) {\n                    sq -= bq; \n                    sell.emplace(sp, sq); \n                }\n            }\n        }        \n        int ans = 0; \n        while (size(buy)) { ans = (ans + buy.top().second) % 1\'000\'000\'007; buy.pop(); }\n        while (size(sell)) { ans = (ans + sell.top().second) % 1\'000\'000\'007; sell.pop(); }\n        return ans; \n    }\n};\n```
['C']