Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- typedef pair<int, int> T;
- public:
- vector<int> assignTasks(vector<int>& servers, vector<int>& tasks) {
- priority_queue<T, vector<T>, greater<T>> fs;
- int n = servers.size(), m=tasks.size();
- for(int i=0; i<n; i++)
- fs.push({servers[i], i});
- priority_queue<T, vector<T>, greater<T>> us;
- int j=0, curTime=0;
- vector<int> ans;
- while(j<m){
- curTime = max(j, curTime);
- if(fs.empty())
- curTime = us.top().first;
- while(!us.empty() && curTime>=us.top().first){
- auto ser = us.top(); us.pop();
- fs.push({servers[ser.second], ser.second});
- }
- if(!fs.empty()){
- auto ser = fs.top(); fs.pop();
- ans.push_back(ser.second);
- us.push({curTime+tasks[j], ser.second});
- j++;
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment