Language: C++

#include<bits/stdc++.h>
using namespace std;
char util(int a, int b, int c)
{
  if(max({a, b, c}) == a)
    	return 'a';
  if(max({a, b, c}) == b)
      	return 'b';
  if(max({a, b, c}) == c)
    	return 'c';
}
char util2(int a, int b, int c)
{
  if(a+b+c - max({a, b, c}) - min({a, b, c}) == a)
    	return 'a';
  if(a+b+c - max({a, b, c}) - min({a, b, c}) == b)
    	return 'b';
  if(a+b+c - max({a, b, c}) - min({a, b, c}) == c)
    	return 'c';
}
int main()
{
  int n;
  cin>>n;
  int a[n], b[n], c[n];
  for(int i=0; i<n; i++)
    cin>>a[i]>>b[i]>>c[i];
  int dp1[n], dp2[n];
  int c1, c2;
  if(max({a[0], b[0], c[0]}) == a[0])
  {
    	c1 = 'a';
    	dp2[0] = max(b[0], c[0]);
    	if(max(b[0], c[0]) == b[0]) 	c2 = 'b';
   		else 	c2 = 'c';
  }
  if(max({a[0], b[0], c[0]}) == b[0])
  {
    	c1 = 'b';
    	dp2[0] = max(a[0], c[0]);
    	if(max(a[0], c[0]) == a[0]) 	c2 = 'a';
   		else 	c2 = 'c';
  }
  if(max({a[0], b[0], c[0]}) == c[0])
  {
    	c1 = 'c';
    	dp2[0] = max(b[0], a[0]);
    	if(max(b[0], a[0]) == b[0]) 	c2 = 'b';
   		else 	c2 = 'a';
  }
  dp1[0] = max({a[0], b[0], c[0]});
    for(int i=1; i<n; i++)
    {
        if(c1 != util(a[i], b[i], c[i]))
        {
          dp1[i] = dp1[i-1] + max({a[i], b[i], c[i]});
          c1 = util(a[i], b[i], c[i]);
        }
        else
        {
          dp1[i] = max(dp1[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i]),
                       dp2[i-1] + max({a[i], b[i], c[i]}) );
          if( dp1[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i])<
                       dp2[i-1] + max({a[i], b[i], c[i]}) )
            	c1 = util({a[i], b[i], c[i]});
          else
            	c1 = util2(a[i], b[i], c[i]]});
        }
        if(c2 != util(a[i], b[i], c[i]))
        {
          dp2[i] = dp2[i-1] + max({a[i], b[i], c[i]});
          c2 = util(a[i], b[i], c[i]);
        }
        else
        {
          dp2[i] = max(dp2[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i]),
                       dp1[i-1] + max({a[i], b[i], c[i]}) );
          if( dp2[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i])<
                       dp1[i-1] + max({a[i], b[i], c[i]}) )
            	c2 = util({a[i], b[i], c[i]});
          else
            	c2 = util2(a[i], b[i], c[i]]});
        }
    }
    cout<<max(dp1[n-1], cp2[n-1]);
}
      
      
      
      
      
      
      

Compiler output:
a.cc: In function 'int main()':
a.cc:61:103: error: expected '}' before ')' token
   61 |           dp1[i] = max(dp1[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i]),
      |                                                                                      ~                ^
a.cc:63:94: error: expected '}' before ')' token
   63 |           if( dp1[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i])<
      |                                                                             ~                ^
a.cc:65:26: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   65 |                 c1 = util({a[i], b[i], c[i]});
      |                      ~~~~^~~~~~~~~~~~~~~~~~~~
      |                          |
      |                          <brace-enclosed initializer list>
a.cc:3:15: note:   initializing argument 1 of 'char util(int, int, int)'
    3 | char util(int a, int b, int c)
      |           ~~~~^
a.cc:67:44: error: expected ')' before ']' token
   67 |                 c1 = util2(a[i], b[i], c[i]]});
      |                           ~                ^
      |                                            )
a.cc:67:46: error: expected primary-expression before ')' token
   67 |                 c1 = util2(a[i], b[i], c[i]]});
      |                                              ^
a.cc:69:25: error: 'i' was not declared in this scope
   69 |         if(c2 != util(a[i], b[i], c[i]))
      |                         ^
a.cc:71:34: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   71 |           dp2[i] = dp2[i-1] + max({a[i], b[i], c[i]});
      |                               ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided
a.cc:76:59: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   76 |           dp2[i] = max(dp2[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i]),
      |                                                        ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided
a.cc:76:103: error: expected '}' before ')' token
   76 |           dp2[i] = max(dp2[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i]),
      |                                                                                      ~                ^
a.cc:76:85: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   76 |           dp2[i] = max(dp2[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i]),
      |                                                                                  ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided
a.cc:77:38: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   77 |                        dp1[i-1] + max({a[i], b[i], c[i]}) );
      |                                   ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided
a.cc:78:50: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   78 |           if( dp2[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i])<
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided
a.cc:78:94: error: expected '}' before ')' token
   78 |           if( dp2[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i])<
      |                                                                             ~                ^
a.cc:78:76: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   78 |           if( dp2[i-1] + a[i] + b[i] + c[i] - max({a[i], b[i], c[i]}) - min({a[i], b[i], c[i])<
      |                                                                         ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: