File tree 1 file changed +7
-15
lines changed
1 file changed +7
-15
lines changed Original file line number Diff line number Diff line change 3
3
namespace {
4
4
long p1 (const auto &input) {
5
5
long m{0 };
6
- long c{0 };
7
- for (const auto &l : input) {
8
- if (l.empty ()) {
9
- m = std::max (m, c);
10
- c = 0 ;
11
- } else {
12
- c += std::atol (l.c_str ());
13
- }
6
+ for (long c{}; const auto &l : input) {
7
+ c = l.empty () ? 0 : c + std::atol (l.c_str ());
8
+ m = std::max (m, c);
14
9
}
15
- return std::max (m, c) ;
10
+ return m ;
16
11
}
17
12
18
13
long p2 (const auto &input) {
19
- std::vector<long > m{};
20
- long c{0 };
14
+ std::vector<long > m{0 };
21
15
for (const auto &l : input) {
22
16
if (l.empty ()) {
23
- m.emplace_back (-c);
24
- c = 0 ;
17
+ m.emplace_back (0 );
25
18
} else {
26
- c += std::atol (l.c_str ());
19
+ m. back () += - std::atol (l.c_str ());
27
20
}
28
21
}
29
- m.emplace_back (-c);
30
22
std::sort (m.begin (), m.end ());
31
23
return std::abs (m[0 ] + m[1 ] + m[2 ]);
32
24
}
You can’t perform that action at this time.
0 commit comments