Submission #852453

#TimeUsernameProblemLanguageResultExecution timeMemory
852453sofijavelkovskamedians (balkan11_medians)C++17
5 / 100
88 ms12052 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, i; set<int> notused; cin >> n; int a[2*n-1], b[n]; for (i=0; i<n; i++) cin >> b[i]; for (i=1; i<=2*n-1; i++) notused.insert(i); a[0]=b[0]; for (i=1; i<n; i++) { auto it=notused.lower_bound(b[i]); if (b[i]==b[i-1]) { x=*it; it--; y=*it; } if (b[i]>b[i-1]) { x=*it; it++; y=*it; } if (b[i]<b[i-1]) { if (*it!=b[i]) it--; x=*it; it--; y=*it; } a[2*i-1]=x; notused.erase(x); a[2*i]=y; notused.erase(y); } for (i=0; i<2*n-1; i++) cout << a[i] << " "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...