#include<bits/stdc++.h>
#define int long long
using namespace std;
struct Node{
int s,t,id;
}a[200005];
struct node{
int t,id;
}b[400005][10];
int tot[10];
inline bool cmp(Node x1,Node x2){
return x1.s<x2.s;
}
inline void work(int x,int op){
if(x*2+1<=tot[op]&&((op==0&&(b[x][op].id>b[x*2+1][op].id&&b[x*2][op].id>b[x*2+1][op].id)||(op==1&&(b[x][op].t>b[x*2+1][op].t||(b[x][op].t==b[x*2+1][op].t&&b[x][op].id>b[x*2+1][op].id))&&(b[x*2][op].t>b[x*2+1][op].t||(b[x*2][op].t==b[x*2+1][op].t&&b[x*2][op].id>b[x*2+1][op].id)))))){
swap(b[x][op],b[x*2+1][op]);
work(x*2+1,op);
}
else if(x*2<=tot[op]&&((op==0&&b[x*2][op].id<b[x][op].id)||(op==1&&(b[x*2][op].t<b[x][op].t||(b[x][op].t==b[x*2][op].t&&b[x][op].id>b[x*2][op].id))))){
swap(b[x][op],b[x*2][op]);
work(x*2,op);
}
}
inline void work1(int x,int op){
if(x!=1&&((op==0&&b[x/2][op].id>b[x][op].id)||(op==1&&(b[x/2][op].id>b[x/2][op].id||(b[x/2][op].t==b[x][op].t&&b[x/2][op].id>b[x][op].id))))){
swap(b[x][op],b[x/2][op]);
work1(x/2,op);
}
}
vector<int>ans[200005];
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i].t>>a[i].s;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=m;i++){
b[++tot[1]][1]={0,i};
}
for(int i=1;i<=n;i++){
while(tot[1]&&b[1][1].t<=a[i].s){
b[++tot[0]][0]=b[1][1];
work1(tot[0],0);
swap(b[1][1],b[tot[1]][1]);
--tot[1];
work(1,1);
}
if(tot[0]){
ans[b[1][0].id].push_back(a[i].id);
b[++tot[1]][1]={a[i].s+a[i].t,b[1][0].id};
work1(tot[1],1);
swap(b[1][0],b[tot[0]][0]);
--tot[0];
work(1,0);
}
else{
ans[b[1][1].id].push_back(a[i].id);
node az={b[1][1].t+a[i].t,b[1][1].id};
swap(b[1][1],b[tot[1]][1]);
--tot[1];
work(1,1);
b[++tot[1]][1]=az;
work1(tot[1],1);
}
}
for(int i=1;i<=m;i++){
cout<<ans[i].size()<<' ';
sort(ans[i].begin(),ans[i].end());
for(auto it:ans[i]){
cout<<it<<' ';
}
cout<<'\n';
}
return 0;
}
如问你问我为什么不用优先队列,那就是不会。