C++ | priority Queue | solution
\nclass Solution {\npublic:\n    int mod = 1e9+7;\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        priority_queue<pair<int, int>>buy;\n
```\nclass Solution {\npublic:\n    int mod = 1e9+7;\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<pair<int, int>>> sell;\n        for(auto x : orders)\n        {\n            int cnt = x[1];\n            if(x[2]==1)\n            {                               \n                while(!buy.empty() && cnt)\n                {                                       // if orderType is sell, then we look for\n                    int f = buy.top().first;            //all largest value in buy, and decrease the amount  \n                    if(f>=x[0])\n                    {\n                        int s = buy.top().second;\n                        buy.pop();\n                        int  mn = min(s, cnt);           \n                        s -= mn;\n                        cnt -=mn; \n                        if(s) buy.push({f, s});\n                    }else break; \n                }\n                if(cnt) sell.push({x[0], cnt}); // if still amount is left we push into sell heap\n            }\n            else\n            {\n                while(!sell.empty() && cnt)\n                {                                       // if orderType is buy, then we look for\n                    int f = sell.top().first;          //all smallest value in sell, and decrease the amount  \n                    if(f<=x[0])\n                    {\n                        int s = sell.top().second;  \n                        sell.pop();    \n                        int  mn = min(s, cnt);        \n                        s -= mn;\n                        cnt -=mn; \n                        if(s) sell.push({f, s});\n                    }else break;\n                }\n                if(cnt) buy.push({x[0], cnt});  // if still amount is left we push into buy heap\n            }\n        }\n        // calculating remaining orders\n        int ans = 0;\n        while(!sell.empty())\n        {\n            ans = (ans + sell.top().second)%mod;\n            sell.pop();\n        }\n         while(!buy.empty())\n        {\n            ans = (ans + buy.top().second)%mod;\n            buy.pop();\n        }\n        return ans%mod;\n    }\n};\n```
['Heap (Priority Queue)']