two priority queue
\n# Code\n\nclass Solution {\npublic:\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        priority_queue<pair<int,int>> buyOrders;\n      
\n# Code\n```\nclass Solution {\npublic:\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        priority_queue<pair<int,int>> buyOrders;\n        priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> sellOrders;\n        int diff;\n        for(auto&x:orders){\n          if(x[2]==0) buyOrders.push({x[0], x[1]});\n          else sellOrders.push({x[0], x[1]});\n\n          while(!buyOrders.empty() && !sellOrders.empty() && buyOrders.top().first>=sellOrders.top().first){\n            auto buyStock=buyOrders.top();\n            auto sellStock=sellOrders.top();\n            buyOrders.pop();sellOrders.pop();\n            diff = buyStock.second-sellStock.second;\n            if(diff<0){\n                sellOrders.push({sellStock.first, abs(diff)});\n            } else if(diff>0){\n                buyOrders.push({buyStock.first, diff});\n            }\n          }\n        }\n\n        int res=0, mod=1e9+7;\n        while(!buyOrders.empty()){\n            res = (res+buyOrders.top().second)%mod;\n            buyOrders.pop();\n        }\n        while(!sellOrders.empty()){\n            res = (res+sellOrders.top().second)%mod;\n            sellOrders.pop();\n        }\n        return res;\n        \n    }\n};\n```
['C++']