→題目鏈接←
【想說的話】
聽說03年不讓用stl...
所以就會產生這樣的題...
【題解】
用優先隊列按照題意模擬就好了
【代碼】
#include<bits/stdc++.h>
using namespace std;
struct node{
int num,ti,t,x;
friend bool operator < (node a,node b){
if(a.x==b.x)return a.ti>b.ti;
return a.x<b.x;
}
};
int a,b,c,d,T=0;
priority_queue<node>q;
int main(){
while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
while(!q.empty() && T<b){
node tmp=q.top();
q.pop();
T=max(T,tmp.ti);
int s=min(b-T,tmp.t);
T+=s;
tmp.t-=s;
if(tmp.t)q.push(tmp);
else printf("%d %d\n",tmp.num,T);
}
q.push((node){a,b,c,d});
}
while(!q.empty()){
node tmp=q.top();
q.pop();
printf("%d %d\n",tmp.num,T+=tmp.t);
}
return 0;
}