代码莫名其妙报错,VSCode没有检测出来语法错误,但一编译运行就会炸掉。
Code
#include <bits/stdc++.h>
using namespace std;
struct Node {
int id, ret, wkt, pri;
bool operator < (Node x) {
return !(pri != x.pri ? pri > x.pri : ret < x.ret);
}
};
signed main() {
priority_queue<Node> pq;
Node now;
int sum = 0;
while (~scanf("%d%d%d%d", &now.id, &now.ret, &now.wkt, &now.pri)) {
while (!pq.empty() && sum + pq.top().wkt <= now.ret) {
printf("%d %d\n", pq.top().id, sum + pq.top().wkt);
sum += pq.top().wkt;
pq.pop();
}
if (!pq.empty()) {
Node tmp = pq.top();
pq.pop();
tmp.wkt -= now.ret - sum;
pq.push(tmp);
}
pq.push(now);
sum = now.ret;
}
while (!pq.empty()) {
printf("%d %d\n", pq.top().id, sum += pq.top().wkt);
// cout << "QWQ:" << pq.size() << '\n';
pq.pop();
}
return 0;
}