C++ | maintain Priority queue of busy servers and keep free server in diff place for fast look up
cpp\nclass Node {\npublic:\n    int end;\n    int serverId;\n};\n\n//min heap comparator\nbool operator< (const Node &a, const Node &b) {\n    return a.end > b.
```cpp\nclass Node {\npublic:\n    int end;\n    int serverId;\n};\n\n//min heap comparator\nbool operator< (const Node &a, const Node &b) {\n    return a.end > b.end;\n}\n\nclass Solution {\npublic:\n    vector<int> busiestServers(int k, vector<int>& arrival, vector<int>& load) {\n        priority_queue<Node> busyServer;        \n        set<int> freeServer;\n        int n = load.size();\n        unordered_map<int, int> serverLoad;\n        for (int i = 0; i < k; ++i) {\n            freeServer.insert(i);\n        }\n        int loadSoFar = 0;\n        int res = 0;\n        for (int i = 0; i < n; ++i) {\n            int start = arrival[i];\n            int duration = load[i];\n            //pick all the servers\n            //which have become free now;\n            while (busyServer.size() > 0 && busyServer.top().end <= start) {\n                freeServer.insert(busyServer.top().serverId);\n                busyServer.pop();\n            }\n            //If there is a server available\n            //then pick it\n            if (freeServer.size() > 0) {\n                auto it = freeServer.lower_bound(i % k);\n                if (it == freeServer.end()) {\n                    it = freeServer.begin();\n                }\n                int serverId = *it;\n                freeServer.erase(it);\n                busyServer.push({start + duration, serverId});\n                ++serverLoad[serverId];\n                if (serverLoad[serverId] > loadSoFar) {\n                    res = serverId;\n                    loadSoFar = serverLoad[serverId];\n                }                    \n            }\n        }\n        vector<int> result;\n        for (pair<int, int> e: serverLoad) {\n            if (e.second == loadSoFar) {\n                result.push_back(e.first);\n            }\n        }\n        return result;\n    }\n};\n```
[]