Original port transfer door
Use the pile simulation operating system
Codeļ¼
#include <bits/stdc++.h>
#define maxn 1000010
using namespace std;
struct heap{
int id, st, t, level;
bool operator < (const heap &x) const {
return x.level == level ? x.st < st : x.level > level; }
};
priority_queue <heap> q;
int id[maxn], st[maxn], t[maxn], level[maxn], n;
int main(){
freopen("1.txt", "r", stdin);
while (~scanf("%d%d%d%d", &id[n + 1], &st[n + 1], &t[n + 1], &level[n + 1])) ++n;
st[n + 1] = 2e9;
for (int i = 1; i <= n; ++i){
q.push((heap){
id[i], st[i], t[i], level[i]});
int s = st[i];
while (!q.empty()){
heap tmp = q.top(); q.pop();
if (tmp.t <= st[i + 1] - s) s += tmp.t, printf("%d %d\n", tmp.id, s);
else{
tmp.t -= (st[i + 1] - s); q.push(tmp); break; }
}
}
return 0;
}