//每日堆排序走一遭
```
#include [HTML_REMOVED]
#include [HTML_REMOVED]
using namespace std;
const int N = 100010;
int n, m;
int h[N], sizes;
void down(int u){
int t = u;
if (2 * u <= sizes && h[2 * u] < h[t]) t = 2 * u;
if (2 * u + 1 <= sizes && h[2 * u + 1] < h[t]) t = 2 * u + 1;
if (t != u){
swap(h[u], h[t]);
down(t);
}
}
void up(int u){
while (u / 2 && h[u / 2] > h[u]){
swap(h[u / 2], h[u]);
u /= 2;
}
}
int main(){
scanf(“%d%d”, &n, &m);
for (int i = 1; i <= n; i ++ ) scanf("%d", &h[i]);
sizes = n;
for (int i = n / 2; i >= 1; i -- ) down(i);
while (m--)
{
printf("%d ", h[1]);
h[1] = h[sizes];
sizes --;
down(1);
}
return 0;
}
···