记录编号 |
606662 |
评测结果 |
AAAAAAAAAA |
题目名称 |
3719.有n种物品 |
最终得分 |
100 |
用户昵称 |
xuyuqing |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.363 s |
提交时间 |
2025-10-01 16:58:03 |
内存使用 |
3.81 MiB |
显示代码纯文本
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int n;
vector<pair<int, int>> nums;
long long res;
bool cmp (pair<int, int> one, pair<int, int> two) {
return one.first - one.second > two.first - two.second;
}
int main () {
cin >> n;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
nums.emplace_back(a, b);
}
sort (nums.begin(), nums.end(), cmp);
int cc = 0;
for (auto [a, b] : nums) {
if (a >= b) {
res += (cc % 2 ? -1 : 1) * (a - b);
}
else {
res += (a - b);
}
cc++;
}
cout << res << endl;
return 0;
}