1216 - [HNOI2003]操作系统

模拟题(题解bymod998244353

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node {
	int id,t1,t2,lvl;
	node(int a=0,int b=0,int c=0,int d=0) {
		id=a;
		t1=b;
		t2=c;
		lvl=d;
	}
	bool operator<(const node b) const {
		return b.lvl^lvl?b.lvl>lvl:t1>b.t1;
	}
} p,u;
priority_queue<node>q;
int a,b,c,d;
ll t;
int main() {
	while(~scanf("%d%d%d%d",&a,&b,&c,&d)) {
		p=node(a,b,c,d);
		while(!q.empty()&&t<b) {
			u=q.top();
			q.pop();
			if(t+u.t2>b) {
				u.t2-=b-t;
				t=b;
				q.push(u);
				break;
			}
			t+=u.t2;
			printf("%d %lld\n",u.id,t);
		}
		if(t<b)t=b;
		q.push(p);
	}
	while(!q.empty()) {
		u=q.top();
		q.pop();
		t+=u.t2;
		printf("%d %lld\n",u.id,t);
	}
	return 0;
}