Language: C++

#include <iostream>
#include <algorithm>
using namespace std;
int n, m;
long long int x[1000], y[1000], z[1000];
long long int dp[8][1000][1000];
long long int dp7(int n1, int m1){
	if(m1 == 0){
		return dp[7][n1 - 1][m1] = 0;
	}
	if(n1 == 0){
		return dp[7][n1 - 1][m1] = 0;
	}
	if(n1 - 1 < m1){
		return dp[7][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) - x[n1 - 1] - y[n1 - 1] - z[n1 - 1];
	}
	return dp[7][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) - x[n1 - 1] - y[n1 - 1] - z[n1 - 1], dp0(n1 - 1, m1));
}
long long int dp6(int n1, int m1){
	if(m1 == 0){
		return dp[6][n1 - 1][m1] = 0;
	}
	if(n1 == 0){
		return dp[6][n1 - 1][m1] = 0;
	}
	if(n1 - 1 < m1){
		return dp[6][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) - x[n1 - 1] - y[n1 - 1] + z[n1 - 1];
	}
	return dp[6][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) - x[n1 - 1] - y[n1 - 1] + z[n1 - 1], dp0(n1 - 1, m1));
}
long long int dp5(int n1, int m1){
	if(m1 == 0){
		return dp[5][n1 - 1][m1] = 0;
	}
	if(n1 == 0){
		return dp[5][n1 - 1][m1] = 0;
	}
	if(n1 - 1 < m1){
		return dp[5][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) - x[n1 - 1] + y[n1 - 1] - z[n1 - 1];
	}
	return dp[5][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) - x[n1 - 1] + y[n1 - 1] - z[n1 - 1], dp0(n1 - 1, m1));
}
long long int dp4(int n1, int m1){
	if(m1 == 0){
		return dp[4][n1 - 1][m1] = 0;
	}
	if(n1 == 0){
		return dp[4][n1 - 1][m1] = 0;
	}
	if(n1 - 1 < m1){
		return dp[4][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) - x[n1 - 1] + y[n1 - 1] + z[n1 - 1];
	}
	return dp[4][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) - x[n1 - 1] + y[n1 - 1] + z[n1 - 1], dp0(n1 - 1, m1));
}
long long int dp3(int n1, int m1){
	if(m1 == 0){
		return dp[3][n1 - 1][m1] = 0;
	}
	if(n1 == 0){
		return dp[3][n1 - 1][m1] = 0;
	}
	if(n1 - 1 < m1){
		return dp[3][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) + x[n1 - 1] - y[n1 - 1] - z[n1 - 1];
	}
	return dp[3][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) + x[n1 - 1] - y[n1 - 1] - z[n1 - 1], dp0(n1 - 1, m1));
}
long long int dp2(int n1, int m1){
	if(m1 == 0){
		return dp[2][n1 - 1][m1] = 0;
	}
	if(n1 == 0){
		return dp[2][n1 - 1][m1] = 0;
	}
	if(n1 - 1 < m1){
		return dp[2][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) + x[n1 - 1] - y[n1 - 1] + z[n1 - 1];
	}
	return dp[2][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) + x[n1 - 1] - y[n1 - 1] + z[n1 - 1], dp0(n1 - 1, m1));
}
long long int dp1(int n1, int m1){
	if(m1 == 0){
		return dp[1][n1 - 1][m1] = 0;
	}
	if(n1 == 0){
		return dp[1][n1 - 1][m1] = 0;
	}
	if(n1 - 1 < m1){
		return dp[1][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) + x[n1 - 1] + y[n1 - 1] - z[n1 - 1];
	}
	return dp[1][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) + x[n1 - 1] + y[n1 - 1] - z[n1 - 1], dp0(n1 - 1, m1));
}
long long int dp0(int n1, int m1){
	if(m1 == 0){
		return dp[0][n1 - 1][m1] = 0;
	}
	if(n1 == 0){
		return dp[0][n1 - 1][m1] = 0;
	}
	if(n1 - 1 < m1){
		return dp[0][n1 - 1][m1] = p0(n1 - 1, m1 - 1) + x[n1 - 1] + y[n1 - 1] + z[n1 - 1];
	}
	return dp[0][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) + x[n1 - 1] + y[n1 - 1] + z[n1 - 1], dp0(n1 - 1, m1));
}
int main(){
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		cin >> x[i] >> y[i] >> z[i];
	}
	for(int i = 0;i < 8;i++){
		for(int j = 0;i < 1000;j++){
			for(int k = 0;k < 1000;k++){
				dp[i][j][k] = -100000000000000;
			}
		}
	}
	cout << max(dp0(n, m), dp1(n, m), dp2(n, m), dp3(n, m), dp4(n, m), dp5(n, m), dp6(n, m), dp7(n, m)) << endl;
}

Compiler output:
a.cc: In function 'long long int dp7(int, int)':
a.cc:15:44: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   15 |                 return dp[7][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) - x[n1 - 1] - y[n1 - 1] - z[n1 - 1];
      |                                            ^~~
      |                                            dp7
a.cc:17:40: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   17 |         return dp[7][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) - x[n1 - 1] - y[n1 - 1] - z[n1 - 1], dp0(n1 - 1, m1));
      |                                        ^~~
      |                                        dp7
a.cc: In function 'long long int dp6(int, int)':
a.cc:27:44: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   27 |                 return dp[6][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) - x[n1 - 1] - y[n1 - 1] + z[n1 - 1];
      |                                            ^~~
      |                                            dp7
a.cc:29:40: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   29 |         return dp[6][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) - x[n1 - 1] - y[n1 - 1] + z[n1 - 1], dp0(n1 - 1, m1));
      |                                        ^~~
      |                                        dp7
a.cc: In function 'long long int dp5(int, int)':
a.cc:39:44: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   39 |                 return dp[5][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) - x[n1 - 1] + y[n1 - 1] - z[n1 - 1];
      |                                            ^~~
      |                                            dp7
a.cc:41:40: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   41 |         return dp[5][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) - x[n1 - 1] + y[n1 - 1] - z[n1 - 1], dp0(n1 - 1, m1));
      |                                        ^~~
      |                                        dp7
a.cc: In function 'long long int dp4(int, int)':
a.cc:51:44: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   51 |                 return dp[4][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) - x[n1 - 1] + y[n1 - 1] + z[n1 - 1];
      |                                            ^~~
      |                                            dp7
a.cc:53:40: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   53 |         return dp[4][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) - x[n1 - 1] + y[n1 - 1] + z[n1 - 1], dp0(n1 - 1, m1));
      |                                        ^~~
      |                                        dp7
a.cc: In function 'long long int dp3(int, int)':
a.cc:63:44: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   63 |                 return dp[3][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) + x[n1 - 1] - y[n1 - 1] - z[n1 - 1];
      |                                            ^~~
      |                                            dp7
a.cc:65:40: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   65 |         return dp[3][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) + x[n1 - 1] - y[n1 - 1] - z[n1 - 1], dp0(n1 - 1, m1));
      |                                        ^~~
      |                                        dp7
a.cc: In function 'long long int dp2(int, int)':
a.cc:75:44: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   75 |                 return dp[2][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) + x[n1 - 1] - y[n1 - 1] + z[n1 - 1];
      |                                            ^~~
      |                                            dp7
a.cc:77:40: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   77 |         return dp[2][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) + x[n1 - 1] - y[n1 - 1] + z[n1 - 1], dp0(n1 - 1, m1));
      |                                        ^~~
      |                                        dp7
a.cc: In function 'long long int dp1(int, int)':
a.cc:87:44: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   87 |                 return dp[1][n1 - 1][m1] = dp0(n1 - 1, m1 - 1) + x[n1 - 1] + y[n1 - 1] - z[n1 - 1];
      |                                            ^~~
      |                                            dp7
a.cc:89:40: error: 'dp0' was not declared in this scope; did you mean 'dp7'?
   89 |         return dp[1][n1 - 1][m1] = max(dp0(n1 - 1, m1 - 1) + x[n1 - 1] + y[n1 - 1] - z[n1 - 1], dp0(n1 - 1, m1));
      |                                        ^~~
      |                                        dp7
a.cc: In function 'long long int dp0(int, int)':
a.cc:99:44: error: 'p0' was not declared in this scope; did you mean 'dp0'?
   99 |                 return dp[0][n1 - 1][m1] = p0(n1 - 1, m1 - 1) + x[n1 - 1] + y[n1 - 1] + z[n1 - 1];
      |                                            ^~
      |                                            dp0
a.cc: In function 'int main()':
a.cc:115:20: error: no matching function for call to 'max(long long int, long long int, long long int, long long int, long long int, long long int, long long int, long long int)'
  115 |         cout << max(dp0(n, m), dp1(n, m), dp2(n, m), dp3(n, m), dp4(n, m), dp5(n, m), dp6(n, m), dp7(n, m)) << endl;
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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, 8 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, 8 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/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:   candidate expects 1 argument, 8 provided
/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, 8 provided