[C++] Simple O(nlogn) solution sorted available servers & current requests
Idea : Maintain a list of available servers in a ordered set. \nWhen a new request arrives, take the first available server by using lower_bound on the set, if 
Idea : Maintain a list of available servers in a ordered set. \nWhen a new request arrives, take the first available server by using lower_bound on the set, if we reach end of set, use the first server in the set. \nAssign the free server the request and maintain this in a set of `<finish-time, server-id>`.\n\nTo get servers who have finished execution, before assigning a new request, just check the server requests set and remove completed requests and mark these servers available.\n\nTo identify the busiest server(s), maintain a count of requests handled by each server and use it after all the requests are completed.\n\nTime complexity : O(nlogn)\nSpace complexity : O(k)\n```\nclass Solution {\npublic:\n    vector<int> busiestServers(int k, vector<int>& arrival, vector<int>& load) {\n        vector<int> handled_requests(k);\n        set<pair<int, int>> current_requests;\n        set<int> available_servers;\n        for(int i = 0; i < k; i++) {\n            available_servers.insert(i);\n        }\n\n        for(int i = 0; i < arrival.size(); i++) {\n            while(!current_requests.empty()) {\n                auto x = current_requests.begin();\n                if(x->first <= arrival[i]) {\n                    available_servers.insert(x->second); // add in available servers\n                    current_requests.erase(current_requests.begin());\n                } else {\n                    break;\n                }\n            }\n            int server_id = i % k;\n            if(available_servers.size() == 0) {\n                continue;\n            }\n            auto it = available_servers.lower_bound(server_id);\n            if(it == available_servers.end()) {\n                // cyclic behaviour\n                it = available_servers.begin();\n            }\n            int u = *it;\n            available_servers.erase(u); // remove from available servers\n            handled_requests[u]++;\n\n            current_requests.insert({arrival[i] + load[i], u});\n        }\n        \n        vector<int> ans;\n        int m = *max_element(handled_requests.begin(), handled_requests.end());\n        for(int i = 0; i < k; i++) {\n            if(handled_requests[i] == m) {\n                ans.push_back(i);\n            }\n        }\n        return ans;\n    }\n};\n```
[]