c++ | easy | fast
\n\n# Code\n\nclass Solution {\npublic:\n       int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        priority_queue<vector<int>>buy;\n        pr
\n\n# Code\n```\nclass Solution {\npublic:\n       int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        priority_queue<vector<int>>buy;\n        priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>>sell;\n        for (auto& o : orders) {\n            if (o[2] == 0)\n                buy.push(o);\n            else\n                sell.push(o);\n            while (buy.size() && sell.size() && sell.top()[0] <= buy.top()[0]) {\n                int k = min(buy.top()[1], sell.top()[1]);\n                vector<int> tmp = buy.top(); buy.pop();\n                tmp[1] -= k;\n                if (tmp[1]) buy.push(tmp);\n\n                tmp = sell.top(); sell.pop();\n                tmp[1] -= k;\n                if (tmp[1]) sell.push(tmp);\n            }\n\n        }\n        int res = 0, mod = 1e9 + 7;\n        while (sell.size())\n            res = (res + sell.top()[1]) % mod, sell.pop();\n        while (buy.size())\n            res = (res + buy.top()[1]) % mod, buy.pop();\n        return res;\n    }\n};\n```
['C++']