记录编号 |
606678 |
评测结果 |
AAAAAAAAAA |
题目名称 |
3719.有n种物品 |
最终得分 |
100 |
用户昵称 |
hsl_beat |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.345 s |
提交时间 |
2025-10-01 20:26:55 |
内存使用 |
3.96 MiB |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
bool cmp(pair<int, int> a, pair<int, int> b)
{
return a.first + b.second > b.first + a.second;
}
signed main()
{
freopen("nit.in", "r", stdin);
freopen("nit.out", "w", stdout);
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end(), cmp);
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++) {
if (a[i].first >= a[i].second) {
if (i & 1) {
cnt1 += a[i].second;
cnt2 += a[i].first;
} else {
cnt1 += a[i].first;
cnt2 += a[i].second;
}
} else {
cnt1 += a[i].first;
cnt2 += a[i].second;
}
}
cout << cnt1 - cnt2;
return 0;
}