forked from abeaumont/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc.cc
More file actions
35 lines (31 loc) · 586 Bytes
/
Copy pathc.cc
File metadata and controls
35 lines (31 loc) · 586 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// https://codeforces.com/contest/1038/problem/C
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<ll, ll> ii;
const int N = 2*100000;
ii a[N];
int main() {
int n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
a[i] = {x, 0};
}
for (int i = n; i < 2*n; i++) {
cin >> x;
a[i] = {x, 1};
}
sort(a, a+2*n, greater<ii>());
ll d = 0;
for (int i = 0; i < 2*n; i++) {
int t = i % 2;
ll k, p;
tie(k, p) = a[i];
if (t == p) {
if (t == 0) d += k;
else d -= k;
}
}
cout << d << endl;
}