#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
set<int> G;
void addmin() {
int v = *G.begin();
cout << v << ' ';
G.erase(G.find(v));
}
void addmax() {
int v = *(--G.end());
cout << v << ' ';
G.erase(G.find(v));
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
int pre, v;
while (cin >> n) {
G.clear();
for (int i = 1; i <= 2 * n - 1; ++i) {
G.insert(i);
}
cin >> v;
cout << v << ' ';
pre = v;
G.erase(G.find(pre));
for (int i = 1; i < n; ++i) {
cin >> v;
if (v > pre) {
if (G.find(v) == G.end()) {
addmax();
addmax();
}else {
addmax();
G.erase(G.find(v));
cout << v << ' ';
}
}else if(v == pre) {
addmin();
addmax();
}else if(v < pre) {
if (G.find(v) == G.end()) {
addmin();
addmin();
}else {
addmin();
G.erase(G.find(v));
cout << v << ' ';
}
}
pre = v;
}
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
8 ms |
792 KB |
Output is correct |
3 |
Correct |
11 ms |
1272 KB |
Output is correct |
4 |
Correct |
19 ms |
2172 KB |
Output is correct |
5 |
Correct |
34 ms |
3960 KB |
Output is correct |
6 |
Correct |
66 ms |
7544 KB |
Output is correct |
7 |
Correct |
109 ms |
11640 KB |
Output is correct |