-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1281.cc
69 lines (63 loc) · 1.57 KB
/
1281.cc
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
61
62
63
64
65
66
67
68
69
//Name: MANAGER
//Level: 2
//Category: シミュレーション
//Note:
#include <iostream>
#include <set>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(0);
bool first = true;
while(true) {
int N;
if(!(cin >> N)) break;
if(!first) cout << endl;
first = false;
int L;
cin >> L;
vector<int> v(L);
for(int i = 0; i < L; ++i) cin >> v[i];
sort(v.begin(), v.end());
multiset<int> q;
int policy = 1;
int remove_cnt = 0;
vector<int>::iterator it = v.begin();
while(true) {
string cmd;
cin >> cmd;
if(cmd == "a") {
int n;
cin >> n;
q.insert(n);
}
else if(cmd == "r") {
int removal = -1;
if(q.size() > 0) {
if(policy == 1) {
removal = *q.begin();
q.erase(q.begin());
}
else {
removal = *q.rbegin();
q.erase(removal);
}
}
++remove_cnt;
if(it != v.end() && remove_cnt == *it) {
cout << removal << endl;
++it;
}
}
else if(cmd == "p") {
cin >> policy;
}
else if(cmd == "e") {
break;
}
}
}
return 0;
}