forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavoidland.cpp
49 lines (38 loc) · 822 Bytes
/
avoidland.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll process(vector<ll>& v) {
vector<ll> doubled;
vector<ll> missing;
for(int i = 1; i < v.size(); i++) {
if(v[i] == 0) {
missing.push_back(i);
}
for(int j = v[i]; j > 1; j--) {
doubled.push_back(i);
}
}
ll total = 0;
for(int i = 0; i < doubled.size(); i++) {
total += abs(doubled[i] - missing[i]);
}
return total;
}
int main() {
ll n;
cin >> n;
vector<ll> hz, vt;
hz.resize(n+1, 0);
vt.resize(n+1, 0);
for(int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
hz[x]++;
vt[y]++;
}
ll total = 0;
total += process(hz);
total += process(vt);
cout << total << endl;
}