C# Solution | Using Sorted Set and Min Heap | Beats 100%
IntuitionPosting this solution for the C# coders.
Solution shows how to solve it using c# SortedSet and Priority Queue without getting TLE.There is a way to mim
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Posting this solution for the C# coders. 
Solution shows how to solve it using c# SortedSet and Priority Queue without getting TLE.

There is a way to mimick Java TreeSet ceiling funtion in c# using SortedSet.GetViewBetween() function.

# Approach
<!-- Describe your approach to solving the problem. -->
You already have seen the right approach to solve it using Priority Queue (Min heap) to store the next available time of each server.
And use a SortedSet to retrieve the next available server.

# 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 IList<int> BusiestServers(int k, int[] arrival, int[] load) {
        IList<int> output = new List<int>();
        SortedSet<int> servers = new SortedSet<int>();
        PriorityQueue<List<int>, int> heap = new PriorityQueue<List<int>, int>(k);
        int[] counts = new int[k];
        int mc = 0;

        for(int i = 0; i < k; i++) {
            servers.Add(i);
        }

        for(int i = 0; i < arrival.Length; i++) {
            // freeing any server 
            while(heap.Count > 0 && heap.Peek()[1] <= arrival[i]) {
                List<int> s = heap.Dequeue();
                servers.Add(s[0]);
            }

            // assigning server if possible
            int server = i % k;
            if (servers.Count == 0) {
                continue;
            }

            if (!servers.Contains(server)) {
                // assign this server
                if (servers.Max > server) {
                    var new_s = servers.GetViewBetween(server, servers.Max);
                    if (new_s.Count > 0) {
                        server = new_s.Min;
                    }
                    else {
                        server = servers.Min;
                    }
                }
                else {
                    server = servers.Min;
                }
            }

            heap.Enqueue(new List<int> {server, arrival[i] + load[i]}, arrival[i] + load[i]);
            servers.Remove(server);
            counts[server]++;

            mc = Math.Max(mc, counts[server]);
        }

        for(int i = 0; i < counts.Length; i++) {
            if (counts[i] == mc) {
                output.Add(i);
            }
        }

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