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: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: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:80:26: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   80 |                 c2 = 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:82:44: error: expected ')' before ']' token
   82 |                 c2 = util2(a[i], b[i], c[i]]});
      |                           ~                ^
      |                                            )
a.cc:82:46: error: expected primary-expression before ')' token
   82 |                 c2 = util2(a[i], b[i], c[i]]});
      |                                              ^
a.cc: At global scope:
a.cc:85:5: error: 'cout' does not name a type
   85 |     cout<<max(dp1[n-1], cp2[n-1]);
      |     ^~~~
a.cc:86:1: error: expected declaration before '}' token
   86 | }
      | ^
a.cc: In function 'char util(int, int, int)':
a.cc:11:1: warning: control reaches end of non-void function [-Wreturn-type]
   11 | }
      | ^
a.cc: In function 'char util2(int, int, int)':
a.cc:20:1: warning: control reaches end of non-void function [-Wreturn-type]
   20 | }
      | ^