Simple Approach using Heap
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#pragma GCC optimize("03","Ofast","inline","fast-math","unroll-loops","no-stack-protector","-ffast-math")\n#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native","f16c")\n#define ll long long int\n#define pp pair<ll,ll>\nclass Solution {\npublic:\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n        priority_queue<pp,vector<pp>,greater<pp>> sellOrder;\n        priority_queue<pp> buyOrder;\n        \n        for(int i=0;i<orders.size();i++)\n        {\n            ll price= orders[i][0];\n            ll amount= orders[i][1];\n            ll orderType= orders[i][2];\n\n            if(orderType==0) //Buy order -> check sell order\n            {\n                //checking the first condition -> if sellOrder is not empty and its smallerEqual to Buy\n                //we pop from it, till we have the amount>0\n                while(amount > 0 && !sellOrder.empty() && sellOrder.top().first <= price)\n                {\n                    auto [sell_price, sell_amount] = sellOrder.top(); sellOrder.pop();\n                    if(sell_amount > amount)\n                    {\n                        sell_amount -= amount;\n                        amount = 0;\n                        sellOrder.push({sell_price, sell_amount});\n                    }\n                    else\n                    {\n                        amount -= sell_amount;\n                    }\n                }\n                //once the amount becomes 0 or sellOrder becomes empty\n                //or the above condition becomes false\n                //fill the buyOrder\n                if(amount > 0) buyOrder.push({price, amount});\n            }\n            else if(orderType==1) //Sell order -> check buy order\n            {\n                //checking the first condition -> if buyOrder is not empty and its greaterEqual to Sell\n                //we pop from it, till we have the amount>0\n                while(amount > 0 && !buyOrder.empty() && buyOrder.top().first >= price)\n                {\n                    auto [buy_price, buy_amount] = buyOrder.top(); buyOrder.pop();\n                    if(buy_amount > amount)\n                    {\n                        buy_amount -= amount;\n                        amount = 0;\n                        buyOrder.push({buy_price, buy_amount});\n                    }\n                    else\n                    {\n                        amount -= buy_amount;\n                    }\n                }\n                //once the amount becomes 0 or sellOrder becomes empty\n                //or the above condition becomes false\n                //fill the buyOrder\n                if(amount > 0) sellOrder.push({price, amount});\n            }\n        }\n\n        ll buyOrder_backlog_size =0;\n        ll sellOrder_backlog_size=0;\n        ll mod = 1000000007;\n\n        while(!buyOrder.empty())\n        {\n            buyOrder_backlog_size = (buyOrder_backlog_size + buyOrder.top().second) % mod;\n            buyOrder.pop();\n        }\n        while(!sellOrder.empty())\n        {\n            sellOrder_backlog_size = (sellOrder_backlog_size + sellOrder.top().second) % mod;\n            sellOrder.pop();\n        }\n        return (buyOrder_backlog_size + sellOrder_backlog_size) % mod; \n    }\n};\n```
['C++']