1
struct compareMin {
2
bool operator()(pair<int, string> p1, pair<int, string> p2) {
3
if (p1.first == p2.first) return p1.second < p2.second;
4
return p1.first > p2.first;
5
}
6
};
7

8
struct compareMax {
9
bool operator()(pair<int, string> p1, pair<int, string> p2) {
10
if (p1.first == p2.first) return p1.second > p2.second;
11
return p1.first < p2.first;
12
}
13
};
14

15
class SORTracker {
16
public:
17
priority_queue<pair<int, string>, vector<pair<int, string>>, compareMin> min_heap;
18
priority_queue<pair<int, string>, vector<pair<int, string>>, compareMax> max_heap;
19

20
SORTracker() {}
21

22
void add(string name, int score) {
23
if (!min_heap.empty() && (min_heap.top().first < score ||
24
(min_heap.top().first == score && min_heap.top().second > name))) {
25
pair<int, string> t = min_heap.top();
26
min_heap.pop();
27
min_heap.push({score, name});
28
max_heap.push(t);
29
} else {
30
max_heap.push({score, name});
31
}
32
}
33

34
string get() {
35
pair<int, string> s = max_heap.top();
36
max_heap.pop();
37
min_heap.push(s);
38
return s.second;
39
}
40
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0