Files
python/GESP/Level5/GESP202503/T1.cpp

36 lines
1008 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
typedef long long LL;
int n;
LL b[N], c[N], d[N];
/*
d n
n C
= B + n
*/
LL ans;
int main() {
2025-09-24 15:40:59 +08:00
// freopen("T1.in", "r", stdin);
2025-08-30 18:35:01 +08:00
cin >> n;
for (int i = 1; i <= 2 * n; i++)
cin >> b[i];
for (int i = 1; i <= 2 * n; i++)
cin >> c[i];
// 初始化为全选小 B 的总收入
for (int i = 1; i <= 2 * n; i++)
ans += b[i];
// 计算每个物品改卖给小 C 的差价
for (int i = 1; i <= 2 * n; i++)
d[i] = c[i] - b[i];
// 排序后取最大的 n 个差价(排序后后半段是最大的)
sort(d + 1, d + 2 * n + 1);
for (int i = n + 1; i <= 2 * n; i++)
ans += d[i];
cout << ans << endl;
return 0;
}