Submission #866078

#TimeUsernameProblemLanguageResultExecution timeMemory
866078Blagojmedians (balkan11_medians)C++17
100 / 100
73 ms11344 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define all(x) x.begin(), x.end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; set<int> notUsed; for (int i = 1; i <= n * 2 - 1; i++) notUsed.insert(i); vector<int> ans, a(n); for (int i = 0; i < n; i++) cin >> a[i]; ans.push_back(a[0]); notUsed.erase(a[0]); for (int i = 1; i < n; i++) { if (a[i] == a[i - 1]) { int mn = *notUsed.begin(), mx = *notUsed.rbegin(); ans.push_back(mn); ans.push_back(mx); notUsed.erase(mn); notUsed.erase(mx); continue; } if (a[i] > a[i - 1]) { int mx = *notUsed.rbegin(); ans.push_back(mx); notUsed.erase(mx); if (notUsed.count(a[i])) { ans.push_back(a[i]); notUsed.erase(a[i]); } else { mx = *notUsed.rbegin(); ans.push_back(mx); notUsed.erase(mx); } continue; } int mn = *notUsed.begin(); ans.push_back(mn); notUsed.erase(mn); if (notUsed.count(a[i])) { ans.push_back(a[i]); notUsed.erase(a[i]); } else { mn = *notUsed.begin(); ans.push_back(mn); notUsed.erase(mn); } } for (auto x : ans) cout << x << " "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...