| 比赛 |
进阶指南第0章测试 |
评测结果 |
AAWWAWWWWW |
| 题目名称 |
有n种物品 |
最终得分 |
30 |
| 用户昵称 |
dbk |
运行时间 |
0.397 s |
| 代码语言 |
C++ |
内存使用 |
3.96 MiB |
| 提交时间 |
2026-03-14 09:44:17 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int a, b, ansa, ansb, f = 1;
priority_queue<pair<int ,pair<int, int>> >q;
int main(){
freopen("nit.in", "r", stdin);
freopen("nit.out", "w", stdout);
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a >> b;
q.push({a - b, {a, b}});
}
while(!q.empty()){
auto now = q.top();q.pop();
if(now.second.first != 0){
if(f == 1){
ansa += now.second.first;
q.push({now.second.second, {0, now.second.second}});
f = 0;
}
else{
ansb += now.second.first;;
q.push({now.second.second, {0, now.second.second}});
f = 1;
}
}
else{
if(f == 1){
ansa += now.second.second;
f = 0;
}
else{
ansb += now.second.second;
f = 1;
}
}
}
cout<<ansa - ansb<<endl;
return 0;
}