Language: C++

#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int sign(int a){
  if (a >= 0)
    return 1;
  else
    return 0;
}

int getid(int a, int b, int c){
  return sign(c) + (sign(b) << 1) + (sign(a) << 2);
}


ll normalize(ll a){
  if (a == -INF)
    return 0;
  else
    return a;
}

int main(void){
  int n, m;
  cin >> n >> m;
  vector<ll> x(n), y(n), z(n);
  for (int i = 0; i < n; i++){
    cin >> x[i] >> y[i] >> z[i];
  }

  vector<vector<vector<tuple<ll, ll, ll>>>> dp(8, vector<vector<tuple<ll, ll, ll>>>(n + 1, vector<tuple<ll, ll, ll>>(m + 1, tuple<ll, ll, ll>(-INF, -INF, -INF))));
  for (int i = 0; i < 8; i++){
    for (int j = 0; j <= n; j++){
      dp[i][j][0] = make_tuple(0, 0, 0);
    }
    dp[i][0][0] = 0;
  }
  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= m; j++){
      for (int k = 0; k < 8; k++){
        ll k1 = get<0>(dp[k][i-1][j-1]);
        ll o1 = get<1>(dp[k][i-1][j-1]);
        ll n1 = get<2>(dp[k][i-1][j-1]);
        ll k2, o2, n2;
        if (k1 != -INF){
          int id = getid(k1 + x[i-1], o1 + y[i-1], n1 + z[i-1]);
          k2 = get<0>(dp[id][i][j]);
          o2 = get<1>(dp[id][i][j]);
          n2 = get<2>(dp[id][i][j]);
          if (abs(normalize(k2)) + abs(normalize(o2)) + abs(normalize(n2)) < abs(k1 + x[i-1]) + abs(o1 + y[i-1]) + abs(n1 + z[i-1])){
            dp[id][i][j] = make_tuple(k1 + x[i-1], o1 + y[i-1], n1 + z[i-1]);
          }
          else {
            ;
          }
        }
        k2 = get<0>(dp[k][i][j]);
        o2 = get<1>(dp[k][i][j]);
        n2 = get<2>(dp[k][i][j]);
        ll k3 = get<0>(dp[k][i-1][j]);
        ll o3 = get<1>(dp[k][i-1][j]);
        ll n3 = get<2>(dp[k][i-1][j]);
        if (k3 == -INF)
          continue;
        if (abs(normalize(k2)) + abs(normalize(o2)) + abs(normalize(n2)) < abs(k3) + abs(o3) + abs(n3)){
          dp[k][i][j] = make_tuple(k3, o3, n3);
        }
        else {
          ;
        }
      }
    }
  }
  ll res = 0;
  for (int i = 0; i < 8; i++){
    ll k = normalize(get<0>(dp[i][n][m]));
    ll o = normalize(get<1>(dp[i][n][m]));
    ll a = normalize(get<2>(dp[i][n][m]));
    ll hoge = abs(k) + abs(o) + abs(a);
    res = max(res, hoge);
  }
  cout << res << endl;


  return 0;
}

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:48:19: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::tuple<long long int, long long int, long long int> >, std::tuple<long long int, long long int, long long int> >::value_type' {aka 'std::tuple<long long int, long long int, long long int>'} and 'int')
   48 |     dp[i][0][0] = 0;
      |                   ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/tuple:1930:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<const _UElements& ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(const std::tuple<_Args1 ...>&) [with _UElements = {_UElements ...}; _Elements = {long long int, long long int, long long int}]'
 1930 |         operator=(const tuple<_UElements...>& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1930:9: note:   template argument deduction/substitution failed:
a.cc:48:19: note:   mismatched types 'const std::tuple<_UTypes ...>' and 'int'
   48 |     dp[i][0][0] = 0;
      |                   ^
/usr/include/c++/14/tuple:1940:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<_UElements ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(std::tuple<_Args1 ...>&&) [with _UElements = {_UElements ...}; _Elements = {long long int, long long int, long long int}]'
 1940 |         operator=(tuple<_UElements...>&& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1940:9: note:   template argument deduction/substitution failed:
a.cc:48:19: note:   mismatched types 'std::tuple<_UTypes ...>' and 'int'
   48 |     dp[i][0][0] = 0;
      |                   ^
/usr/include/c++/14/tuple:1907:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&>) [with _Elements = {long long int, long long int, long long int}; std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&> = const std::tuple<long long int, long long int, long long int>&]'
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1909:52: note:   no known conversion for argument 1 from 'int' to 'std::__conditional_t<true, const std::tuple<long long int, long long int, long long int>&, const std::__nonesuch&>' {aka 'const std::tuple<long long int, long long int, long long int>&'}
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1908 |                                 const tuple&,
      |                                 ~~~~~~~~~~~~~       
 1909 |                                 const __nonesuch&> __in)
      |                                 ~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/14/tuple:1918:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&>) [with _Elements = {long long int, long long int, long long int}; std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&> = std::tuple<long long int, long long int, long long int>&&]'
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1920:47: note:   no known conversion for argument 1 from 'int' to 'std::__conditional_t<true, std::tuple<long long int, long long int, long long int>&&, std::__nonesuch&&>' {aka 'std::tuple<long long int, long long int, long long int>&&'}
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1919 |                                 tuple&&,
      |                                 ~~~~~~~~       
 1920 |                                 __nonesuch&&> __in)
      |                                 ~~~~~~~~~~~~~~^~~~