```cpp
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
struct task{ //任务进程
int num,tim,rank;
task (int a, int c, int d) {
num=a,tim=c,rank=d;
}
};
int a,b,c,d,now;
bool operator < (task x, task y) { //维护大根堆
if(x.rank!=y.rank) return x.rank<y.rank;
return x.num>y.num;
}
__gnu_pbds::priority_queue <task> q; //建立优先队列
int main()
{
while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF){
while(!q.empty()){
task top=q.top(); //还有时间剩余,进行下一个进程
q.pop();
if(now+top.tim<=b){ //如果有剩余时间(不被打断),正常出队
now+=top.tim;
printf("%d %d\n",top.tim,now);
}
else{ //如果剩余时间不够(被打断),剩余进程入队
top.tim-=(b-now); //减去已经完成的进度
q.push(top);
break; //没事剩余时间,跳出循环
}
}
q.push(task(a,c,d)); //将进程入队
now=b; //更新当前时间
}
while(!q.empty()){ //不再有进程到达
task top=q.top();
q.pop();
now+=top.tim; //更新当前时间
printf("%d %d\n",top.tim, now);
}
return 0;
}
```
by Explorer_CYC @ 2018-05-19 19:56:43