'commit'
This commit is contained in:
36
GESP/Level5/Test3.cpp
Normal file
36
GESP/Level5/Test3.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
const int N = 2e5 + 10;
|
||||
struct Node {
|
||||
int id; // 哪个物品
|
||||
int cha; // 差值
|
||||
} a[N];
|
||||
int cmp(Node a, Node b) { return a.cha < b.cha; }
|
||||
int b[N], c[N];
|
||||
LL sum;
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= 2 * n; i++)
|
||||
cin >> b[i];
|
||||
|
||||
for (int i = 1; i <= 2 * n; i++)
|
||||
cin >> c[i];
|
||||
|
||||
for (int i = 1; i <= 2 * n; i++) {
|
||||
a[i].id = i;
|
||||
a[i].cha = c[i] - b[i];
|
||||
}
|
||||
sort(a + 1, a + 2 * n + 1, cmp);
|
||||
|
||||
for (int i = 1; i <= n; i++)
|
||||
sum += b[a[i].id];
|
||||
|
||||
for (int i = n + 1; i <= 2 * n; i++)
|
||||
sum += c[a[i].id];
|
||||
|
||||
cout << sum;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user