From d795bc862e2261b9354291a4f50feab051f5a3f0 Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Sat, 30 Nov 2024 23:37:34 -0800 Subject: [PATCH] 2024 day 1 --- 2024/1/main-1.cpp | 28 ++++++++++++++++++++++++++++ 2024/1/main-2.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 2024/1/main-1.cpp create mode 100644 2024/1/main-2.cpp diff --git a/2024/1/main-1.cpp b/2024/1/main-1.cpp new file mode 100644 index 0000000..50dac40 --- /dev/null +++ b/2024/1/main-1.cpp @@ -0,0 +1,28 @@ +#include +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + vector l1, l2; + string line; + while (getline(cin, line) && !line.empty()) { + istringstream l(line); + int a, b; + l >> a >> b; + l1.push_back(a); + l2.push_back(b); + } + + sort(l1.begin(), l1.end()); + sort(l2.begin(), l2.end()); + + long long result = 0; + for (auto i = 0; i < l1.size(); i++) { + result += abs(l1[i] - l2[i]); + } + + cout << result << '\n'; +} diff --git a/2024/1/main-2.cpp b/2024/1/main-2.cpp new file mode 100644 index 0000000..6548294 --- /dev/null +++ b/2024/1/main-2.cpp @@ -0,0 +1,26 @@ +#include +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + vector l1; + multiset l2; + string line; + while (getline(cin, line) && !line.empty()) { + istringstream l(line); + int a, b; + l >> a >> b; + l1.push_back(a); + l2.insert(b); + } + + long long result = 0; + for (auto i : l1) { + result += i * l2.count(i); + } + + cout << result << '\n'; +}