题目:https://www.patest.cn/contests/gplt/L3-010
#include<bits/stdc++.h>
using namespace std;
const int maxn=505;
int T[maxn];
void update(int x,int pos){
if(!T[pos]){
T[pos]=x;
return;
}
if(x>=T[pos])
update(x,pos*2);
else
update(x,pos*2+1);
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
update(x,1);
}
int flg=0,cnt=0;
for(int i=1;i<50;i++){
if(!T[i]){
flg=1;
continue;
}
cnt++;
cout<<T[i];
if(cnt==n){
cout<<endl;
break;
}
else cout<<" ";
}
if(flg)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
return 0;
}