Heap | cpp
\nclass Solution\n{\n    public:\n        struct cmp\n        {\n            bool operator()(pair<int, int> a, pair<int, int> b)\n            {\n               
```\nclass Solution\n{\n    public:\n        struct cmp\n        {\n            bool operator()(pair<int, int> a, pair<int, int> b)\n            {\n                return a.first > b.first;\n            }\n        };\n    void fun(priority_queue<pair<int, int>, vector< pair<int, int>>, cmp> &sell, priority_queue< pair<int, int>> &buy)\n    {\n        while (buy.size() and sell.size() and buy.top().first >= sell.top().first)\n        {\n            auto x = buy.top();\n            auto y = sell.top();\n            buy.pop();\n            sell.pop();\n            if (x.second < y.second)\n            {\n                y.second -= x.second;\n                x.second = 0;\n                sell.push(y);\n            }\n            else if (y.second < x.second)\n            {\n                x.second -= y.second;\n                y.second = 0;\n                buy.push(x);\n            }\n            else\n            {\n                x.second = 0;\n                y.second = 0;\n            }\n        }\n    }\n    int getNumberOfBacklogOrders(vector<vector < int>> &orders)\n    {\n        int mod = 1e9 + 7;\n        priority_queue<pair<int, int>, vector< pair<int, int>>, cmp> sell;\n        priority_queue<pair<int, int>> buy;\n        long ans = 0;\n        for (int x = 0; x < orders.size(); x++)\n        {\n            if (orders[x][2] == 1) sell.push({ orders[x][0],orders[x][1] });\n            else buy.push({ orders[x][0],orders[x][1] });\n\n            fun(sell, buy);\n        }\n        fun(sell, buy);\n        while (buy.size())\n        {\n            ans = (ans + buy.top().second) % mod;\n            buy.pop();\n        }\n        while (sell.size())\n        {\n            ans = (ans + sell.top().second) % mod;\n            sell.pop();\n        }\n        return ans;\n    }\n};\n```
['C++']