#include <bits/stdc++.h>
using namespace std;
const int N = 1'007;
int n;
int t[N];
bool used[N << 1];
bool blocked[N << 1];
void do_pref(){
for(int i = 1; i < (n << 1); i++){
if(blocked[i] || used[i]) continue;
cout << i << ' ';
used[i] = true;
return;
}
}
void do_suf(){
for(int i = (n << 1) - 1; i >= 1; i--){
if(blocked[i] || used[i]) continue;
cout << i << ' ';
used[i] = true;
return;
}
}
void calc(int x){
int pref = 0;
int suf = 0;
for(int i = 1; i < x; i++){
if(used[i]) pref++;
}
for(int i = x+1; i < (n << 1); i++){
if(used[i]) suf++;
}
if(pref < suf) do_pref();
else if(pref > suf) do_suf();
else {
do_pref();
do_suf();
}
}
void solve(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> t[i];
blocked[t[i]] = true;
}
cout << t[0] << ' ';
used[t[0]] = true;
for(int i = 1; i < n; i++){
if(!used[t[i]]){
cout << t[i] << ' ';
used[t[i]] = true;
}
calc(t[i]);
}
cout << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |