-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ32.cpp
More file actions
60 lines (52 loc) · 1.25 KB
/
Copy pathQ32.cpp
File metadata and controls
60 lines (52 loc) · 1.25 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <string>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
vector<int> solution(vector<string> operations) {
priority_queue<int> pq1;
priority_queue<int, vector<int>, greater<int>> pq2;
for (string op : operations) {
if (op[0] == 'I') {
pq1.push(stoi(op.substr(2)));
continue;
}
if (op[2] == '-') {
while (!pq1.empty()) {
pq2.push(pq1.top());
pq1.pop();
}
if (pq2.empty()) {
continue;
}
pq2.pop();
continue;
}
while (!pq2.empty()) {
pq1.push(pq2.top());
pq2.pop();
}
if (pq1.empty()) {
continue;
}
pq1.pop();
}
if (pq1.empty() && pq2.empty()) {
return vector<int> {0, 0};
}
int mn = 2100000000;
int mx = 0;
while (!pq1.empty()) {
int val = pq1.top();
pq1.pop();
mn = min(mn, val);
mx = max(mx, val);
}
while (!pq2.empty()) {
int val = pq2.top();
pq2.pop();
mn = min(mn, val);
mx = max(mx, val);
}
return vector<int> {mx, mn};
}