This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
}else {
G.erase(G.find(v));
cout << v << ' ';
}
addmax();
}else if(v == pre) {
addmin();
addmax();
}else if(v < pre) {
if (G.find(v) == G.end()) {
addmin();
}else {
G.erase(G.find(v));
cout << v << ' ';
}
addmin();
}
pre = v;
}
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |