-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ28.cpp
More file actions
34 lines (28 loc) · 778 Bytes
/
Copy pathQ28.cpp
File metadata and controls
34 lines (28 loc) · 778 Bytes
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
#include <algorithm>
#include <deque>
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> priorities, int location) {
int answer = 0;
deque<int> dq(priorities.begin(), priorities.end());
sort(priorities.rbegin(), priorities.rend());
int most = 0;
int curLocation = location;
while (true) {
int cur = dq.front();
dq.pop_front();
if (cur < priorities[most]) {
dq.push_back(cur);
curLocation = curLocation == 0 ? dq.size() - 1 : curLocation - 1;
continue;
}
most++;
answer++;
if (curLocation == 0) {
break;
}
curLocation = curLocation == 0 ? dq.size() - 1 : curLocation - 1;
}
return answer;
}