C++ || Priority Queue || Set || Beat 77%
\nclass Solution {\npublic:\n    vector<int> busiestServers(int k, vector<int>& arrival, vector<int>& load) {\n        int n = (int)arrival.size();\n        \n 
```\nclass Solution {\npublic:\n    vector<int> busiestServers(int k, vector<int>& arrival, vector<int>& load) {\n        int n = (int)arrival.size();\n        \n        set<int> freeServers;\n        for (int i = 0; i < k; i++) freeServers.insert(i);\n        \n        vector<int> serverTaskCount(k, 0);\n        \n        set<pair<int, int>> workingServers;     // [end time, server index]\n        for (int i = 0; i < n; i++) {\n            int startTime = arrival[i];\n            \n            while (!workingServers.empty() && workingServers.begin()->first <= startTime) {\n                auto s = *workingServers.begin();\n                workingServers.erase(workingServers.begin());\n                freeServers.insert(s.second);\n            }\n            \n            if (freeServers.empty()) continue;\n            \n            int serverIndex = -1;\n            auto it = freeServers.lower_bound(i % k);\n            if (it == freeServers.end()) {\n                serverIndex = *freeServers.begin();\n                freeServers.erase(freeServers.begin());\n            } else {\n                serverIndex = *it;\n                freeServers.erase(it);\n            }\n            \n            workingServers.insert({startTime + load[i], serverIndex});\n            \n            serverTaskCount[serverIndex]++;\n            //printf("Task %d (%d, %d) assigned to server %d\\n", i, startTime, load[i], serverIndex);\n        }\n        // for (auto x : serverTaskCount) cout << x << " ";\n        // cout << endl;\n        \n        vector<int> ret;\n        int maxVal = *max_element(serverTaskCount.begin(), serverTaskCount.end());\n        for (int i = 0; i < k; i++) \n            if (maxVal == serverTaskCount[i]) ret.push_back(i);\n        \n        return ret;\n    }\n};\n```
['C', 'Heap (Priority Queue)', 'Ordered Set']