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
```csharp []
public class Solution {
    public int GetNumberOfBacklogOrders(int[][] orders) {
        PriorityQueue<int[], int> buy = new();
        PriorityQueue<int[], int> sell = new();

        foreach(var order in orders)
        {
            if(order[2] == 0)
            {
                while(sell.Count>0 && sell.Peek()[0]<=order[0] && order[1]>0)
                {
                    if(order[1]>=sell.Peek()[1])
                    {
                        order[1] -= sell.Peek()[1];
                        sell.Dequeue();
                    }
                    else
                    {
                        sell.Peek()[1] -= order[1];
                        order[1] = 0;
                    }
                }
                if(order[1]>0)
                {
                    buy.Enqueue(order, -1*order[0]);
                }
            }
            else
            {
                while(buy.Count>0 && buy.Peek()[0]>=order[0] && order[1]>0)
                {
                    if(order[1]>=buy.Peek()[1])
                    {
                        order[1] -= buy.Peek()[1];
                        buy.Dequeue();
                    }
                    else
                    {
                        buy.Peek()[1] -= order[1];
                        order[1] = 0;
                    }
                }
                if(order[1]>0)
                {
                    sell.Enqueue(order, order[0]);
                }
            }
        }

        int ans = 0;
        while(sell.Count>0)
        {
            ans= (ans+sell.Peek()[1])%(1000000000+7);
            sell.Dequeue();
        }
        while(buy.Count>0)
        {
            ans = (ans+buy.Peek()[1])%(1000000000+7);
            buy.Dequeue();
        }

        return ans;
    }
}
```
['C#']