-
Notifications
You must be signed in to change notification settings - Fork 0
/
nus.99problems.cpp
46 lines (43 loc) · 1.25 KB
/
nus.99problems.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
45
46
// 99 Problems
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, Q, temp;
cin >> N >> Q;
multiset<int> difficulties;
for (int i = 0; i < N; ++i) {
cin >> temp;
difficulties.insert(temp);
}
set<int> discarded;
for (int i = 0; i < Q; ++i) {
int T, D;
cin >> T >> D;
multiset<int>::iterator dit;
if (T == 1) {
dit = difficulties.upper_bound(D);
}
if (T == 2) {
dit = difficulties.lower_bound(D); // returns >=
if (dit == difficulties.end() && difficulties.size() > 0) { // [6], Q = 7
--dit;
} else if (*dit > D && *dit != D) { // dit <= D
if (dit == difficulties.begin()) { // [6], Q = 5
dit = difficulties.end();
} else {
--dit;
}
}
}
if (dit != difficulties.end()) {
cout << *dit << '\n';
discarded.insert(*dit);
difficulties.erase(dit);
} else {
cout << "-1\n";
}
}
return 0;
}