#include<bits/stdc++.h>
using namespace std;
struct Node{
int ID;
int t; //命令下发时间
int s; //打印所需时间
bool operator< (const Node &b) const{
return this->t > b.t;
}
};
priority_queue<Node>text;
struct Node_1{
int t_out;
int ID;
int tp;
bool used;
//根据打印机最后一个任务的结束时间大小和编号进行排序
bool operator< (const Node_1 &b) const{
return this->t_out != b.t_out ? this->t_out>b.t_out :this->ID >b.ID ;
}
};
priority_queue<Node_1>printer;
struct Node_2{
int ID;
vector<int>text;
int num;
};
vector<Node_2>printer_out;
bool cmp(Node_2 a,Node_2 b){
return a.ID>b.ID;
}
int n,m;
//中间量
Node_1 now_1;
Node_2 now_2;
int main(){
cin>>n>>m;
//打印机初始化,m个空打印机
for(int i=0;i<m;i++){
now_1.ID=i+1;
printer.push(now_1);
}
Node now;
for(int i=0;i<n;i++){
cin>>now.s>>now.t;
now.ID=i+1;
text.push(now);
}
for(int i=0;i<n;i++){
//每份文件的打印时间为[t,t+s)
now_1.ID=printer.top().ID;
now_1.t_out= text.top().t + text.top().s;
if(printer.top().used){
printer_out[printer.top().tp].text.push_back(text.top().ID);
printer_out[printer.top().tp].num++;
}else{
now_1.tp=printer_out.size();
now_2.ID=printer.top().ID;
now_2.text.push_back(text.top().ID);
now_2.num=1;
//now_2的初始化问题,未解决
printer_out.push_back(now_2);
}
now_1.used=true;
text.pop();
if(now_1.t_out<=text.top().t){
now_1.t_out=0;
}
printer.pop();
printer.push(now_1);
now_2.text.resize(0);//中间量清理
}
//按打印机编号排序
sort(printer_out.begin(),printer_out.end(),cmp);
for(int i=0;i<m;i++){
cout<<printer_out[i].num<<' ';
for(int j=0;j<printer_out[i].text.size();j++){
cout<<printer_out[i].text[j]<<' ';
}
cout<<endl;
}
return 0;
}