优先队列解法
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+9, INF=1e9;
int n, m;
struct node{int v, id;friend bool operator < (node a, node b){return a.id == b.id ? a.v>=b.v : a.id>=b.id;};
};
vector<int> q[maxn];
int main()
{priority_queue<node, vector<node> > pq; cin >> n >> m;while(pq.size()<m && pq.size()<n){ int t; scanf("%d", &t);pq.push({t, 1});}for(int i = pq.size(); i < n; i++){ int t; scanf("%d", &t);node preout = pq.top(); pq.pop();q[preout.id].push_back(preout.v);t < preout.v ? pq.push({t,preout.id+1}) : pq.push({t, preout.id}); }while(!pq.empty()){ node u = pq.top();q[u.id].push_back(u.v);pq.pop();}int i = 1;while(q[i].size()>0){ for(int j = 0; j < q[i].size(); j++){if(j) putchar(' ');printf("%d", q[i][j]);}cout << endl;i++;}return 0;
}