比赛 |
20251001国庆欢乐赛1 |
评测结果 |
AAAWWWWWWW |
题目名称 |
有n种物品 |
最终得分 |
30 |
用户昵称 |
淮淮清子 |
运行时间 |
0.145 s |
代码语言 |
C++ |
内存使用 |
3.91 MiB |
提交时间 |
2025-10-01 09:01:00 |
显示代码纯文本
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int MAXN = 100005;
struct node{
int a, b;
}p[MAXN], q[MAXN];
int n, tot1 = 0, tot2 = 0;
bool cmp1(node x, node y){
return x.a > y.a;
}
bool cmp2(node x, node y){
return x.b < y.b;
}
int main(){
freopen("nit.in", "r", stdin);
freopen("nit.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i ++){
int x, y; cin >> x >> y;
if(x >= y) p[++ tot1].a = x, p[tot1].b = y;
else q[++ tot2].a = x, q[tot2].b = y;
}
sort(p + 1, p + tot1 + 1, cmp1);
sort(q + 1, q + tot2 + 1, cmp2);
ll A = 0, B = 0;
bool flag = 1;
for(int i = 1;i <= tot1;i ++){
if(flag){
A += p[i].a;
B += p[i].b;
}
else{
B += p[i].a;
A += p[i].b;
}
flag = !flag;
}
flag = 1;
for(int i = 1;i <= tot2;i ++){
A += q[i].a;
B += q[i].b;
}
cout << A - B << '\n';
return 0;
}