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<cstdio>
#include<deque>
using namespace std;
int n,k;
deque<int> tree[100001];
int su[100001];
int sons[100001];
int head;
void bubble(int parent){
int i;
for(i=0;i<sons[parent];i++){
bubble(tree[parent][i]);
}
if(sons[parent]<2) return;
head=tree[parent][0];
for(i=1;i<sons[parent];i++){
if(su[head]>su[tree[parent][i]]){
tree[head].push_back(tree[parent][i]);
}else{
tree[tree[parent][i]].push_front(head);
head=tree[parent][i];
}
sons[head]++;
}
tree[parent].resize(1);
tree[parent][0]=head;
sons[parent]=1;
}
void aprint(int parent){
int i;
for(i=0;i<sons[parent];i++){
aprint(tree[parent][i]);
}
if(parent>0) printf("%d ",su[parent]);
}
int main(){
int i;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++){
scanf("%d",&su[i]);
tree[0].resize(n);
tree[0][i-1]=i;
}
sons[0]=n;
for(i=0;i<k;i++) bubble(0);
aprint(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |