Language: C++

#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <limits.h>

using namespace std;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<array<long long, 3>> xyz(N);
    for (int i=0; i<N; ++i) {
        cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
    }
    vector<long long> tmp(N);
    long long max = 0;
    for (int x: {1, -1}) {
        for (int y: {1, -1}) {
            for (int z: {1, -1}) {
                for (int i=0; i<N; ++i) {
                    tmp[i] = xyz[i][0] * x + xyz[i][1] * y + xyz[i][2] * z;
                }
                sort(tmp.begin(), tmp.end(), greater<long long>());
                long long sum = 0;
                for (int j=0; j<M; ++j) {
                    sum += tmp[j];
                }
                if (sum > max) {
                    max = sum;
                }
            }
        }
    }
    cout << max << '\n';
    return 0;
}

Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:20:22: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} and 'int')
   20 |         cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
      |                      ^
a.cc:20:35: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} and 'int')
   20 |         cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
      |                                   ^
a.cc:20:48: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} and 'int')
   20 |         cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
      |                                                ^
a.cc:28:36: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} and 'int')
   28 |                     tmp[i] = xyz[i][0] * x + xyz[i][1] * y + xyz[i][2] * z;
      |                                    ^
a.cc:28:52: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} and 'int')
   28 |                     tmp[i] = xyz[i][0] * x + xyz[i][1] * y + xyz[i][2] * z;
      |                                                    ^
a.cc:28:68: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 3> >, std::array<long long int, 3> >::value_type' {aka 'std::array<long long int, 3>'} and 'int')
   28 |                     tmp[i] = xyz[i][0] * x + xyz[i][1] * y + xyz[i][2] * z;
      |                                                                    ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >; reference = std::array<long long int, 3>&; size_type = long unsigned int]':
a.cc:20:21:   required from here
   20 |         cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
      |                     ^
/usr/include/c++/14/bits/stl_vector.h:1131:41: error: invalid use of incomplete type 'struct std::array<long long int, 3>'
 1131 |         return *(this->_M_impl._M_start + __n);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 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_pair.h:99:12: note: declaration of 'struct std::array<long long int, 3>'
   99 |     struct array;
      |            ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >]':
/usr/include/c++/14/bits/stl_vector.h:557:47:   required from 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >; size_type = long unsigned int; allocator_type = std::allocator<std::array<long long int, 3> >]'
  557 |       : _Base(_S_check_init_len(__n, __a), __a)
      |                                               ^
a.cc:18:38:   required from here
   18 |     vector<array<long long, 3>> xyz(N);
      |                                      ^
/usr/include/c++/14/bits/stl_vector.h:369:49: error: invalid use of incomplete type 'struct std::array<long long int, 3>'
  369 |                       _M_impl._M_end_of_storage - _M_impl._M_start);
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<long long int, 3>'
   99 |     struct array;
      |            ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'static std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::_S_max_size(const _Tp_alloc_type&) [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >; size_type = long unsigned int; _Tp_alloc_type = std::vector<std::array<long long int, 3> >::_Tp_alloc_type]':
/usr/include/c++/14/bits/stl_vector.h:1919:23:   required from 'static std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::_S_check_init_len(size_type, const allocator_type&) [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >; size_type = long unsigned int; allocator_type = std::allocator<std::array<long long int, 3> >]'
 1919 |         if (__n > _S_max_size(_Tp_alloc_type(__a)))
      |                   ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:557:32:   required from 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >; size_type = long unsigned int; allocator_type = std::allocator<std::array<long long int, 3> >]'
  557 |       : _Base(_S_check_init_len(__n, __a), __a)
      |               ~~~~~~~~~~~~~~~~~^~~~~~~~~~
a.cc:18:38:   required from here
   18 |     vector<array<long long, 3>> xyz(N);
      |                                      ^
/usr/include/c++/14/bits/stl_vector.h:1932:61: error: invalid application of 'sizeof' to incomplete type 'std::array<long long int, 3>'
 1932 |           = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_Tp);
      |                                                             ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'void std::_Vector_base<_Tp, _Alloc>::_M_create_storage(std::size_t) [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >; std::size_t = long unsigned int]':
/usr/include/c++/14/bits/stl_vector.h:334:9:   required from 'std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >; std::size_t = long unsigned int; allocator_type = std::allocator<std::array<long long int, 3> >]'
  334 |       { _M_create_storage(__n); }
      |         ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:557:47:   required from 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >; size_type = long unsigned int; allocator_type = std::allocator<std::array<long long int, 3> >]'
  557 |       : _Base(_S_check_init_len(__n, __a), __a)
      |                                               ^
a.cc:18:38:   required from here
   18 |     vector<array<long long, 3>> xyz(N);
      |                                      ^
/usr/include/c++/14/bits/stl_vector.h:400:66: error: invalid use of incomplete type 'struct std::array<long long int, 3>'
  400 |         this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<long long int, 3>'
   99 |     struct array;
      |            ^~~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/type_traits: In instantiation of 'struct std::is_destructible<std::array<long long int, 3> >':
/usr/include/c++/14/bits/stl_construct.h:188:51:   required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = array<long long int, 3>*]'
  188 |       static_assert(is_destructible<_Value_type>::value,
      |                                                   ^~~~~
/usr/include/c++/14/bits/alloc_traits.h:993:20:   required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator, allocator<_T2>&) [with _ForwardIterator = array<long long int, 3>*; _Tp = array<long long int, 3>]'
  993 |       std::_Destroy(__first, __last);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:735:15:   required from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = std::array<long long int, 3>; _Alloc = std::allocator<std::array<long long int, 3> >]'
  735 |         std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  736 |                       _M_get_Tp_allocator());
      |                       ~~~~~~~~~~~~~~~~~~~~~~
a.cc:18:38:   required from here
   18 |     vector<array<long long, 3>> xyz(N);
      |                                      ^
/usr/include/c++/14/type_traits:1049:52: error: static assertion failed: template argument must be a complete class or an unbounded array
 1049 |       static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/type_traits:1049:52: note: 'std::__is_complete_or_unbounded<__type_identity<array<long long int, 3> > >((std::__type_identity<std::array<long long int, 3> >(), std::__type_identity<std::array<long long int, 3> >()))' evaluates to false
In f