Submission #83534

#TimeUsernameProblemLanguageResultExecution timeMemory
83534Linst90medians (balkan11_medians)C++11
100 / 100
138 ms13132 KiB
#include<iostream> #include<map> using namespace::std; int r,l; map<int,bool> m; void gf(){ while(m.count(l)) ++l; cout<<l<<' '; m[l++]=1; } void gl(){ while(m.count(r)) --r; cout<<r<<' '; m[r--]=1; } int main(){ int n; cin>>n; r=2*n-1; l=1; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; cout<<a[0]<<' '; m[a[0]]=1; for(int i=1;i<n;i++){ if(m.count(a[i])){ if(a[i-1]>a[i]) gf(),gf(); else if(a[i-1]<a[i]) gl(),gl(); else gf(),gl(); }else{ m[a[i]]=1; cout<<a[i]<<' '; if(a[i-1]>a[i]) gf(); else gl(); } } cout<<'\n'; } //129856734
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...