# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499379 | colossal_pepe | medians (balkan11_medians) | C++17 | 1083 ms | 904 KiB |
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 <iostream>
#include <vector>
#include <cstring>
using namespace std;
int n, a[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool mark[2 * n];
memset(mark, 0, sizeof(mark));
vector<int> ans;
for (int i = 0; i < n; i++) {
if (not mark[a[i]]) {
ans.push_back(a[i]);
mark[a[i]] = 1;
}
int kom = 0, beshi = 0;
for (int j = 1; j < 2 * n; j++) {
if (mark[j]) {
if (j < a[i]) kom++;
else if (j > a[i]) beshi++;
}
}
for (int j = i + 1; j < n; j++) {
if (kom < i and a[j] < a[i] and not mark[a[j]]) {
ans.push_back(a[j]);
mark[a[j]] = 1;
kom++;
}
if (beshi < i and a[j] > a[i] and not mark[a[j]]) {
ans.push_back(a[j]);
mark[a[j]] = 1;
beshi++;
}
}
for (int j = 1; j < 2 * n; j++) {
if (kom < i and j < a[i] and not mark[j]) {
ans.push_back(j);
mark[j] = 1;
kom++;
}
if (beshi < i and j > a[i] and not mark[j]) {
ans.push_back(j);
mark[j] = 1;
beshi++;
}
}
}
for (int i : ans) {
cout << i << ' ';
}
cout << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |