C++ Map
Intuition\nWe need to avoid scanning through k servers for every request. So, instead looping through requests, we will loop through servers and take all reques
#### Intuition\nWe need to avoid scanning through `k` servers for every request. So, instead looping through requests, we will loop through servers and take all requests that are available (not picked up by previous servers) and can be handled.\n\n#### Solution\nFor each server, we track when it becomes available (`avail`), and also the count `cnt` of executed requests. We will use that count in the end to determine the busiest server.\n\nFor a current server `i % k`, we add request `i` to the list of available requests. If we can process that request, we remove it from the queue. If not - that request will become available for the next server to pick up. We will pick an earlier request first - to ensure that a request is processed by the first available server.\n\nHere, we are using ordered map to \'queue\' available requests, so it\'s efficient to find requests that the current server can process. We can further optimize by removing \'dropped\' requests.\n\n**C++**\n```cpp\nvector<int> busiestServers(int k, vector<int>& arrival, vector<int>& load) {\n    vector<int> cnt(k), avail(k), res;\n    map<int, int> m;\n    for (int i = 0, last_i = 0; ; ++i) {\n        if (i < arrival.size())\n            m[arrival[i]] = load[i];\n        else if (i - last_i > k)\n            break;\n        auto it = m.lower_bound(avail[i % k]);\n        while (it != end(m)) {\n            last_i = i;\n            ++cnt[i % k];\n            avail[i % k] = it->first + it->second;\n            m.erase(it);\n            it = m.lower_bound(avail[i % k]);\n        }\n    }\n    int max_req = *max_element(begin(cnt), end(cnt));\n    for (int i = 0; i < k; ++i)\n        if(cnt[i] == max_req)\n            res.push_back(i);\n    return res;\n}\n```
[]