C++ easy solution using 2 priority queues
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 {
public:
    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {
        priority_queue<pair<int,int>>p;
       priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;

        for(int i=0;i<orders.size();i++)
        {
            if(orders[i][2]==0)
            {
                p.push({orders[i][0],orders[i][1]});
            }
            else{
                pq.push({orders[i][0],orders[i][1]});
              
            }
              while(!p.empty()&&!pq.empty()&&(p.top().first>=pq.top().first))
                {
                    int p1=p.top().first;
                    int q1=p.top().second;
                    int p2=pq.top().first;
                    int q2=pq.top().second;
                    p.pop();
                    pq.pop();
                    if(q1>q2)
                    {
                        q1=q1-q2;
                        p.push({p1,q1});
                    }
                    else if(q2>q1)
                    {
                        q2=q2-q1;
                        pq.push({p2,q2});
                    }
                }                                                                          }
                int ans=0;
                while(!p.empty())
                {
                    ans=(ans+p.top().second)%1000000007;
                    p.pop();
                }
                while(!pq.empty())
                {
                    ans=(ans+pq.top().second)%1000000007;
                    pq.pop();
                }
                return ans;

        
    }
};
```
['C++']