Language: C++

#include<iostream>
#include<vector>

void q_sort(const std::vector<__int64> &vec,std::vector<size_t> &index,int first,int last){
	if(last-first<1){
		return;
	}
	int i=first,j=last;
	for(size_t pivot=first;;i++,j--){
		while(vec[index[i]]<vec[index[pivot]]){
			i++;
		}
		while(vec[index[j]]>vec[index[pivot]]){
			j--;
		}
		if(i>=j){
			break;
		}
		size_t p=index[j];
		index[j]=index[i];
		index[i]=p;
	}
	q_sort(vec,index,first,i-1);
	q_sort(vec,index,j+1,last);
}

int main(){
	//入力機構
	size_t N,M;
	std::cin>>N>>M;
	std::vector<__int64> X,Y,Z;//10,000,000,000の値が入りintだとオーバーする可能性大。
	X.reserve(N);
	Y.reserve(N);
	Z.reserve(N);
	for(size_t i=0;i<N;i++){
		__int64 x,y,z;
		std::cin>>x>>y>>z;
		X.push_back(x);
		Y.push_back(y);
		Z.push_back(z);
	}

	//処理機構
	__int64 ans=0;
	__int64 xAns,yAns,zAns;//それぞれ(綺麗さの合計),(おいしさの合計),(人気度の合計)を指す
	std::vector<__int64> vec;//N個の配列を用意
	vec.reserve(N);
	for(size_t i=0;i<N;i++){
		vec.push_back(0);
	}
	std::vector<size_t> index;
	index.reserve(N);
	for(size_t i=0;i<N;i++){
		index.push_back(0);
	}
	//xAns,yAns,zAnsの全ての正負について考える。計8パターン。
	int pattern[8][3]={{-1,-1,-1},{-1,-1,1},{-1,1,-1},{-1,1,1},{1,-1,-1},{1,-1,1},{1,1,-1},{1,1,1}};
	for(size_t i=0;i<8;i++){
		//各合計を記入
		for(size_t j=0;j<N;j++){
			vec[j]=X[j]*pattern[i][0]+Y[j]*pattern[i][1]+Z[j]*pattern[i][2];
		}
		//vecが大きい順にindexをソート
		for(size_t j=0;j<N;j++){
			index[j]=j;
		}
		q_sort(vec,index,0,N-1);
		xAns=0;
		yAns=0;
		zAns=0;
		for(size_t j=0;j<M;j++){
			xAns+=X[index[j]]*pattern[i][0];
		}
		for(size_t j=0;j<M;j++){
			yAns+=Y[index[j]]*pattern[i][1];
		}
		for(size_t j=0;j<M;j++){
			zAns+=Z[index[j]]*pattern[i][2];
		}
		__int64 pal=std::abs(xAns)+std::abs(yAns)+std::abs(zAns);
		if(ans<pal){
			ans=pal;
		}
	}

	//出力機構
	std::cout<<ans<<std::endl;
	
	return 0;
}


Compiler output:
a.cc:4:31: error: '__int64' was not declared in this scope; did you mean '__int64_t'?
    4 | void q_sort(const std::vector<__int64> &vec,std::vector<size_t> &index,int first,int last){
      |                               ^~~~~~~
      |                               __int64_t
a.cc:4:38: error: template argument 1 is invalid
    4 | void q_sort(const std::vector<__int64> &vec,std::vector<size_t> &index,int first,int last){
      |                                      ^
a.cc:4:38: error: template argument 2 is invalid
a.cc: In function 'void q_sort(const int&, std::vector<long unsigned int>&, int, int)':
a.cc:10:26: error: invalid types 'const int[__gnu_cxx::__alloc_traits<std::allocator<long unsigned int>, long unsigned int>::value_type {aka long unsigned int}]' for array subscript
   10 |                 while(vec[index[i]]<vec[index[pivot]]){
      |                          ^
a.cc:10:40: error: invalid types 'const int[__gnu_cxx::__alloc_traits<std::allocator<long unsigned int>, long unsigned int>::value_type {aka long unsigned int}]' for array subscript
   10 |                 while(vec[index[i]]<vec[index[pivot]]){
      |                                        ^
a.cc:13:26: error: invalid types 'const int[__gnu_cxx::__alloc_traits<std::allocator<long unsigned int>, long unsigned int>::value_type {aka long unsigned int}]' for array subscript
   13 |                 while(vec[index[j]]>vec[index[pivot]]){
      |                          ^
a.cc:13:40: error: invalid types 'const int[__gnu_cxx::__alloc_traits<std::allocator<long unsigned int>, long unsigned int>::value_type {aka long unsigned int}]' for array subscript
   13 |                 while(vec[index[j]]>vec[index[pivot]]){
      |                                        ^
a.cc: In function 'int main()':
a.cc:31:21: error: '__int64' was not declared in this scope; did you mean '__int64_t'?
   31 |         std::vector<__int64> X,Y,Z;//10,000,000,000の値が入りintだとオーバーする可能性大。
      |                     ^~~~~~~
      |                     __int64_t
a.cc:31:28: error: template argument 1 is invalid
   31 |         std::vector<__int64> X,Y,Z;//10,000,000,000の値が入りintだとオーバーする可能性大。
      |                            ^
a.cc:31:28: error: template argument 2 is invalid
a.cc:32:11: error: request for member 'reserve' in 'X', which is of non-class type 'int'
   32 |         X.reserve(N);
      |           ^~~~~~~
a.cc:33:11: error: request for member 'reserve' in 'Y', which is of non-class type 'int'
   33 |         Y.reserve(N);
      |           ^~~~~~~
a.cc:34:11: error: request for member 'reserve' in 'Z', which is of non-class type 'int'
   34 |         Z.reserve(N);
      |           ^~~~~~~
a.cc:36:24: error: expected ';' before 'x'
   36 |                 __int64 x,y,z;
      |                        ^~
      |                        ;
a.cc:37:27: error: 'x' was not declared in this scope
   37 |                 std::cin>>x>>y>>z;
      |                           ^
a.cc:37:30: error: 'y' was not declared in this scope
   37 |                 std::cin>>x>>y>>z;
      |                              ^
a.cc:37:33: error: 'z' was not declared in this scope
   37 |                 std::cin>>x>>y>>z;
      |                                 ^
a.cc:38:19: error: request for member 'push_back' in 'X', which is of non-class type 'int'
   38 |                 X.push_back(x);
      |                   ^~~~~~~~~
a.cc:39:19: error: request for member 'push_back' in 'Y', which is of non-class type 'int'
   39 |                 Y.push_back(y);
      |                   ^~~~~~~~~
a.cc:40:19: error: request for member 'push_back' in 'Z', which is of non-class type 'int'
   40 |                 Z.push_back(z);
      |                   ^~~~~~~~~
a.cc:44:16: error: expected ';' before 'ans'
   44 |         __int64 ans=0;
      |                ^~~~
      |                ;
a.cc:45:16: error: expected ';' before 'xAns'
   45 |         __int64 xAns,yAns,zAns;//それぞれ(綺麗さの合計),(おいしさの合計),(人気度の合計)を指す
      |                ^~~~~
      |                ;
a.cc:46:28: error: template argument 2 is invalid
   46 |         std::vector<__int64> vec;//N個の配列を用意
      |                            ^
a.cc:47:13: error: request for member 'reserve' in 'vec', which is of non-class type 'int'
   47 |         vec.reserve(N);
      |             ^~~~~~~
a.cc:49:21: error: request for member 'push_back' in 'vec', which is of non-class type 'int'
   49 |                 vec.push_back(0);
      |                     ^~~~~~~~~
a.cc:61:28: error: invalid types 'int[size_t {aka long unsigned int}]' for array subscript
   61 |                         vec[j]=X[j]*pattern[i][0]+Y[j]*pattern[i][1]+Z[j]*pattern[i][2];
      |                            ^
a.cc:61:33: error: invalid types 'int[size_t {aka long unsigned int}]' for array subscript
   61 |                         vec[j]=X[j]*pattern[i][0]+Y[j]*pattern[i][1]+Z[j]*pattern[i][2];
      |                                 ^
a.cc:61:52: error: invalid types 'int[size_t {aka long unsigned int}]' for array subscript
   61 |                         vec[j]=X[j]*pattern[i][0]+Y[j]*pattern[i][1]+Z[j]*pattern[i][2];
      |                                                    ^
a.cc:61:71: error: invalid types 'int[size_t {aka long unsigned int}]' for array subscript
   61 |                         vec[j]=X[j]*pattern[i][0]+Y[j]*pattern[i][1]+Z[j]*pattern[i][2];
      |                                                                       ^
a.cc:68:17: error: 'xAns' was not declared in this scope
   68 |                 xAns=0;
      |                 ^~~~
a.cc:69:17: error: 'yAns' was not declared in this scope
   69 |                 yAns=0;
      |                 ^~~~
a.cc:70:17: error: 'zAns' was not declared in this scope
   70 |                 zAns=0;
      |                 ^~~~
a.cc:72:32: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<long unsigned int>, long unsigned int>::value_type {aka long unsigned int}]' for array subscript
   72 |                         xAns+=X[index[j]]*pattern[i][0];
      |                                ^
a.cc:75:32: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<long unsigned int>, long unsigned int>::value_type {aka long unsigned int}]' for array subscript
   75 |                         yAns+=Y[index[j]]*pattern[i][1];
      |                                ^
a.cc:78:32: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<long unsigned int>, long unsigned int>::value_type {aka long unsigned int}]' for array subscript
   78 |                         zAns+=Z[index[j]]*pattern[i][2];
      |                                ^
a.cc:80:24: error: expected ';' before 'pal'
   80 |                 __int64 pal=std::abs(xAns)+std::abs(yAns)+std::abs(zAns);
      |                        ^~~~
      |                        ;
a.cc:81:20: error: 'ans' was not declared in this scope; did you mean 'abs'?
   81 |                 if(ans<pal){
      |                    ^~~
      |                    abs
a.cc:81:24: error: 'pal' was not declared in this scope
   81 |                 if(ans<pal){
      |                        ^~~
a.cc:87:20: error: 'ans' was not declared in this scope; did you mean 'abs'?
   87 |         std::cout<<ans<<std::endl;
      |                    ^~~
      |                    abs