EASY AND UNDERSTANDABLE
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```cpp []\nclass Solution {\npublic:\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        priority_queue<pair<long long,long long>>buy;\n        priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>>sell;\n        for(auto it:orders){\n            int price=it[0];\n            int amount=it[1];\n            int orderType=it[2];\n\n            if(orderType == 0){\n                while(sell.size()!=0){\n                    int p=sell.top().first;\n                    int am=sell.top().second;\n                    if(p<=price){\n                        if(amount == 0){\n                            break;\n                        }\n                        if(amount >= am){\n                            sell.pop();\n                            amount-=am;\n                        }else{\n                            sell.pop();\n                            sell.push({p,am-amount});\n                            amount=0;\n                        }\n                    }else{\n                        break;\n                    }\n\n                }\n                if(amount){\n                    buy.push({price,amount});\n                }\n            }\n            else{\n                while(buy.size()!=0){\n                    int p=buy.top().first;\n                    int am=buy.top().second;\n                    if(p>=price){\n                        if(amount == 0){\n                            break;\n                        }\n                        if(amount >= am){\n                            buy.pop();\n                            amount-=am;\n                        }else{\n                            buy.pop();\n                            buy.push({p,am-amount});\n                            amount=0;\n                        }\n                    }\n                    else{\n                        break;\n                     }\n                    \n                }\n                if(amount){\n                    sell.push({price,amount});\n                }\n            }\n        }\n        int ans=0;\n        while(!sell.empty()){\n            ans=(ans + (sell.top().second)% 1000000007) % 1000000007;\n            sell.pop();\n        }\n        while(!buy.empty()){\n            ans=(ans+ (buy.top().second) % 1000000007) % 1000000007;\n            buy.pop();\n        }\n        return ans;\n    }\n};\n```
['Array', 'Heap (Priority Queue)', 'Simulation', 'C++']