1
0
forked from danmax/aoc

organised 2024 year and added day4 in rust solution

This commit is contained in:
deadvey
2024-12-14 02:27:21 +00:00
parent 8f62314da3
commit 1eb0384e35
30 changed files with 268 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
int main() {
std::ifstream f("b");
std::vector<int> x;
std::vector<int> y;
int l, r;
while (f >> l >> r) {
x.push_back(l);
y.push_back(r);
}
std::sort(x.begin(), x.end());
std::sort(y.begin(), y.end());
long t = 0;
int c = 0;
auto p = y.begin();
for (size_t i = 0; i < 4000000; i++) {
auto b = std::lower_bound(p, y.end(), x[i]);
auto u = std::upper_bound(p, y.end(), x[i]);
int c = u - b;
t += x[i] * c;
p = b;
}
std::cout << t;
return 0;
}