aboutsummaryrefslogtreecommitdiff
path: root/2024/01/day01a.cpp
blob: e4a61e0a927b006687ae2d134b2af46e0ea6f673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int x, y, tot;
	vector<int> v, w;

	while (cin >> x >> y) {
		v.push_back(x);
		w.push_back(y);
	}

	sort(v.begin(), v.end());
	sort(w.begin(), w.end());

	tot = 0;
	for (unsigned i = 0; i < v.size(); i++)
		tot += abs(v[i] - w[i]);

	cout << tot << endl;
	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net