two priority_queue
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
    constexpr static int mod = 1e9 + 7;
public:
    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {
        priority_queue<pair<int, int>, vector<pair<int, int>>, less<>> buy;
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> sell;
        for (const vector<int>& order: orders)
        {
            switch (order.back())
            {
                case 0:
                    buy.emplace(order[0], order[1]);
                    break;
                case 1:
                    sell.emplace(order[0], order[1]);
                    break;
                default:
                    break;
            }
            while (!buy.empty() && !sell.empty() && buy.top().first >= sell.top().first)
            {
                if (const int amount = min(buy.top().second, sell.top().second);
                    buy.top().second > sell.top().second)
                {
                    const int buyPrice = buy.top().first;
                    const int buyAmount = buy.top().second - amount;
                    sell.pop();
                    buy.pop();
                    buy.emplace(buyPrice, buyAmount);
                }
                else if (buy.top().second < sell.top().second)
                {
                    const int sellPrice = sell.top().first;
                    const int sellAmount = sell.top().second - amount;
                    buy.pop();
                    sell.pop();
                    sell.emplace(sellPrice, sellAmount);
                }
                else
                {
                    sell.pop();
                    buy.pop();
                }
            }
        }
        int res = 0;
        while (!buy.empty())
        {
            res = (res + buy.top().second) % mod;
            buy.pop();
        }
        while (!sell.empty())
        {
            res = (res + sell.top().second) % mod;
            sell.pop();
        }
        return res;
    }
};
```
['C++']