C++ solution | priority queues | easy to implement| Beats 100%
we initialise two priority queues, one of buy and other sell, after that we iterate through the orders, \nfor every order , we have two choices:\n-> ordertype i
we initialise two priority queues, one of buy and other sell, after that we iterate through the orders, \nfor every order , we have two choices:\n-> ordertype is `0-buy`, here we check three cases,\n* \t\tif sell.size() ==0, we just push our current order into buy\n* \t\tif sell.top()[0] > p , that means smallest price of sell is greater that current price of buy, so we push into buy\n* \t\tif number of order n>0\nSame with the case of ordertype 1,  \n\nFinally, we count the number of orders left in both `buy` and `sell`\n\n**Please Upvote** if you find it helpful.\n\n```\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(vector<int>temp : orders){\n            int p=temp[0], n = temp[1], t = temp[2];\n            if(t==0){\n                while(sell.size() && sell.top()[0] <= p && n){\n                    vector<int>cur = sell.top();\n                    if(cur[1] > n){\n                        cur[1] -= n;\n                        sell.pop();\n                        sell.push(cur);\n                        n=0;\n                    }else{\n                        n -= cur[1];\n                        sell.pop();\n                    }\n                }\n                if(n) buy.push({p,n,t});\n            }\n            else{\n                while(buy.size() && buy.top()[0]>=p && n){\n                vector<int>cur = buy.top();\n                     if(cur[1] > n){\n                        cur[1] -= n;\n                        buy.pop();\n                        buy.push(cur);\n                        n=0;\n                    }else{\n                        n -= cur[1];\n                        buy.pop();\n                    }\n                }\n                if(n) sell.push({p,n,t});\n            }\n        }  \n        long long int res=0;\n        while(buy.size()>0){\n            res += buy.top()[1];\n            buy.pop();\n        }\n        while(sell.size()>0){\n            res += sell.top()[1];\n            sell.pop();\n        }\n        return res%1000000007;\n    }\n```
[]