| 比赛 |
进阶指南第0章测试 |
评测结果 |
AWWWWWWWWW |
| 题目名称 |
有n种物品 |
最终得分 |
10 |
| 用户昵称 |
ychyyx |
运行时间 |
0.196 s |
| 代码语言 |
C++ |
内存使用 |
4.50 MiB |
| 提交时间 |
2026-03-14 09:12:00 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
int n;
ll a[100005],b[100005];
ll sum[2];
int t;
struct Node{
ll val;
int id;
int g;
bool operator <(const Node b)const{
return val<b.val||val==b.val&&g<b.g;
}
};
priority_queue<Node> q;
int main(){
freopen("nit.in","r",stdin);
freopen("nit.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld %lld",&a[i],&b[i]);
q.push({a[i],i,1});
}
while(!q.empty()){
sum[t%2]+=q.top().val;
if(q.top().g==1){
int i=q.top().id;
q.pop();
q.push({b[i],i,2});
}else
q.pop();
t++;
}
printf("%lld",sum[0]-sum[1]);
return 0;
}