每次输入时 堆顶元素减去时间间隔 now记录当前时间
#include<bits/stdc++.h>
#define maxn 17000
#define ll long long
using namespace std;
struct node{
ll num,arr,cost,val;
};
bool operator<(node x,node y){
if (y.val==x.val) return y.arr<x.arr;
return y.val>x.val;
}
priority_queue<node> q;
ll aa,b,c,d,ii=1,ti[maxn],flag,tim;
ll now;
//号码 到达时间 执行时间 优先级
int main(){
while (~scanf("%lld",&aa)){
scanf("%lld%lld%lld",&b,&c,&d);
node tem={aa,b,c,d};
if (!flag){
tim=b;now=aa;flag=1;
q.push(tem);
continue;
}
int time=b-tim;
// printf("time=%d\n",time);
while (!q.empty()&&time>=q.top().cost&&time){
node fron=q.top();
time-=fron.cost;
now+=fron.cost;
printf("%lld %lld\n",fron.num,now);
q.pop();
}
if (q.empty()){
if (b>now) now=b;
}
if (!q.empty()){
node fron=q.top();
if (time<fron.cost){
node add={fron.num,fron.arr,fron.cost-time,fron.val};
q.pop();
q.push(add);
now+=time;
}
}
// printf("now=%d\n",now);
tim=b;
q.push(tem);
}
// cout<<"now="<<now<<endl;
while (!q.empty()){
node fron=q.top();
now+=fron.cost;
printf("%lld %lld\n",fron.num,now);
q.pop();
}
return 0;
}