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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
int cnt[40];
int val=-1;
void dfs(int v){
bool flag=false;
for(int i=0;i<v;i++){
if(cnt[i]!=0){
flag=true;
}
}
if(!flag){
val=v;
return;
}
if(cnt[v-1]==1){
cnt[v-1]--;
dfs(v-1);
}
else if(cnt[v-1]==0){
dfs(v-1);
dfs(v-1);
}
else if(cnt[v-1]==2){
cnt[v-1]=0;
}
}
signed main(){
int n,k;
cin>>n>>k;
vector <int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
cnt[a[i]]++;
}
dfs(30);
for(int i=0;i<n;i++){
if(a[i]<=val && val!=-1){
cout<<val<<" "<<a[i]<<" ";
val=-1;
}
else{
cout<<a[i]<<" ";
}
}
if(val!=-1){
cout<<val<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |