比赛 |
20251001国庆欢乐赛1 |
评测结果 |
AWWWWWWWWW |
题目名称 |
有n种物品 |
最终得分 |
10 |
用户昵称 |
dream |
运行时间 |
0.420 s |
代码语言 |
C++ |
内存使用 |
4.02 MiB |
提交时间 |
2025-10-01 09:03:36 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
struct node{
ll x,y;
bool operator < (const node &t) const {
if(x==t.x) return y>t.y;
return x<t.x;
}
};
priority_queue<node> q;
ll ans;
int main(){
freopen("nit.in","r",stdin);
freopen("nit.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
ll a,b;
cin>>a>>b;
q.push({a,b});
}
for(int i=1;i<=n*2;i++){
node t=q.top();
q.pop();
if(i&1){
ans+=t.x;
}
else ans-=t.x;
if(t.y!=-1){
q.push({t.y,-1});
}
}
cout<<ans;
return 0;
}