| 比赛 |
进阶指南第0章测试 |
评测结果 |
AWWWWWWWWW |
| 题目名称 |
有n种物品 |
最终得分 |
10 |
| 用户昵称 |
赵飞羽 |
运行时间 |
0.235 s |
| 代码语言 |
C++ |
内存使用 |
4.02 MiB |
| 提交时间 |
2026-03-14 10:42:15 |
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100010;
int n, a, b, ans1, ans2;
struct node{
int x, y;
bool friend operator <(node u, node v) {
if (u.x == v.x) return (u.x - u.y) < (v.x - v.y);
return u.x < v.x;
}
};
priority_queue <node> q;
signed main() {
freopen("nit.in", "r", stdin);
freopen("nit.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a >> b;
q.push({a, b});
}
for (int i = 1; i <= 2 * n; i++) {
node t = q.top();
q.pop();
if (i % 2) ans1 += t.x;
else ans2 += t.x;
q.push({t.y, 0});
}
cout << ans1 - ans2;
return 0;
}