35 lines
896 B
C++
35 lines
896 B
C++
|
#include <algorithm>
|
||
|
#include <fstream>
|
||
|
#include <iostream>
|
||
|
#include <vector>
|
||
|
|
||
|
int main() {
|
||
|
static std::fstream mainFile("/home/theskywinds/Programs/Owned programs/AdventofCode2024/input.txt");
|
||
|
|
||
|
if (!mainFile.is_open()) {
|
||
|
std::cerr << "Failed to open file\n";
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
std::pair<std::vector<int>, std::vector<int>> listPair;
|
||
|
|
||
|
listPair.first.resize(1000);
|
||
|
listPair.second.resize(1000);
|
||
|
int64_t total{0};
|
||
|
int64_t tracker{0};
|
||
|
|
||
|
for (int i = 0; mainFile.good(); i++) {
|
||
|
mainFile >> listPair.first[i] >> listPair.second[i];
|
||
|
tracker++;
|
||
|
}
|
||
|
|
||
|
sort(listPair.first.begin(), listPair.first.end());
|
||
|
sort(listPair.second.begin(), listPair.second.end());
|
||
|
|
||
|
|
||
|
for (size_t i = 0; i < tracker ; i++) {
|
||
|
total += static_cast<int64_t>(std::abs(listPair.first[i] - listPair.second[i]));
|
||
|
}
|
||
|
|
||
|
std::cout << total << '\n';
|
||
|
}
|