-
Notifications
You must be signed in to change notification settings - Fork 6
/
1834.Single-ThreadedCPU.cpp
44 lines (37 loc) · 1.11 KB
/
1834.Single-ThreadedCPU.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> getOrder(vector<vector<int>>& tasks) {
vector<int>ans;
for(int i=0;i<tasks.size();i++){
tasks[i].push_back(i);
}
sort(tasks.begin(),tasks.end());
//
vector<int>flag(tasks.size());
long long start=1,i=0;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
while(i<tasks.size()){
for(;i<tasks.size()&&tasks[i][0]<=start;i++){
pq.push({tasks[i][1],tasks[i][2]});
}
if(pq.empty()){
ans.push_back(tasks[i][2]);
start=tasks[i][1]+tasks[i][0];
i++;
}
else{
ans.push_back(pq.top().second);
start+=pq.top().first;
pq.pop();
}
}
while(pq.size()){
ans.push_back(pq.top().second);
start+=pq.top().first;
pq.pop();
}
return ans;
}
};