summary refs log tree commit diff
path: root/22.1
diff options
context:
space:
mode:
authordzwdz2022-12-01 20:08:55 +0100
committerdzwdz2022-12-01 20:08:55 +0100
commitb2503f5ebed4da42950b8e02cb03e0b9950560e9 (patch)
tree1fde00ffea4acc681132cec6ce5ab57a3aa674d4 /22.1
parent1997482305dab1a3804f084048ff48797339908a (diff)
day 1 part 2
Diffstat (limited to '22.1')
-rw-r--r--22.1/main.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/22.1/main.cpp b/22.1/main.cpp
index 4a33aca..5f7aea6 100644
--- a/22.1/main.cpp
+++ b/22.1/main.cpp
@@ -1,21 +1,29 @@
 #include <algorithm>
+#include <array>
 #include <iostream>
 #include <string>
 using namespace std;
 
 class Solution {
-	long best = -1;
+	array<long, 3> best = {0};
 	long curtotal = 0;
-public:
 
+public:
 	void addItem(long cals) {
 		curtotal += cals;
 	}
 	void endElf() {
-		best = max(best, curtotal);
+		if (best[0] < curtotal) {
+			best[0] = curtotal;
+			// i wonder if the compiler is smart enough to skip the second if
+			// would honestly be pretty terrifying
+			if (best[0] > best[1]) swap(best[0], best[1]);
+			if (best[1] > best[2]) swap(best[1], best[2]);
+		}
 		curtotal = 0;
 	}
-	long getAnswer() { return best; }
+	long getPartOne() { return best[2]; }
+	long getPartTwo() { return best[0] + best[1] + best[2]; }
 };
 
 
@@ -31,5 +39,6 @@ main()
 		}
 	}
 	sol.endElf();
-	cout << sol.getAnswer() << endl;
+	cout << sol.getPartOne() << endl;
+	cout << sol.getPartTwo() << endl;
 }