blob: 5f7aea66627c2337129cb4e7400efe34af922ac2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
using namespace std;
class Solution {
array<long, 3> best = {0};
long curtotal = 0;
public:
void addItem(long cals) {
curtotal += cals;
}
void endElf() {
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 getPartOne() { return best[2]; }
long getPartTwo() { return best[0] + best[1] + best[2]; }
};
int
main()
{
Solution sol;
for (string line; getline(cin, line); ) {
if (line.length() > 0) {
sol.addItem(stol(line));
} else {
sol.endElf();
}
}
sol.endElf();
cout << sol.getPartOne() << endl;
cout << sol.getPartTwo() << endl;
}
|