题目:
题解:
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int si,m;
int h[N];
void down(int x){
int t=x;
if(x*2<=si&&h[t]>h[x*2])t=x*2;
if(x*2+1<=si&&h[t]>h[x*2+1])t=x*2+1;
if(t!=x){
swap(h[t],h[x]);
down(t);
}
}
int main(){
scanf("%d%d",&si,&m);
for(int i=1;i<=si;i++)scanf("%d",h+i);
for(int i=si/2;i;i--)down(i);
while(m--){
printf("%d ",h[1]);
h[1]=h[si--];
down(1);
}
return 0;
}