summary refs log tree commit diff
path: root/22.1/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '22.1/main.cpp')
-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;
 }