File tree Expand file tree Collapse file tree 1 file changed +7
-15
lines changed Expand file tree Collapse file tree 1 file changed +7
-15
lines changed Original file line number Diff line number Diff line change 33namespace  {
44long  p1 (const  auto  &input) {
55  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);
149  }
15-   return  std::max (m, c) ;
10+   return  m ;
1611}
1712
1813long  p2 (const  auto  &input) {
19-   std::vector<long > m{};
20-   long  c{0 };
14+   std::vector<long > m{0 };
2115  for  (const  auto  &l : input) {
2216    if  (l.empty ()) {
23-       m.emplace_back (-c);
24-       c = 0 ;
17+       m.emplace_back (0 );
2518    } else  {
26-       c  += std::atol (l.c_str ());
19+       m. back ()  += - std::atol (l.c_str ());
2720    }
2821  }
29-   m.emplace_back (-c);
3022  std::sort (m.begin (), m.end ());
3123  return  std::abs (m[0 ] + m[1 ] + m[2 ]);
3224}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments