Language: C++


#include <iostream>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cstdlib>
using namespace std;

long long ans = -1;

struct data {
    long long b,t,p;
};

void combinations_recursive(const vector<data> &elems, unsigned long req_len,
                            vector<unsigned long> &pos, unsigned long depth,
                            unsigned long margin)
{
    // Have we selected the number of required elements?
    if (depth >= req_len) {
        long long sum = 0;
        long long sumB = 0,sumT = 0,sumP = 0;
        for (unsigned long ii = 0; ii < pos.size(); ++ii)
        {
            sumB += elems[pos[ii]].b;
            sumT += elems[pos[ii]].t;
            sumP += elems[pos[ii]].p;
            
        }
        sum = abs(sumB) + abs(sumT) + abs(sumP);
        if (sum > ans)
            ans = sum;
        return;
    }
    
    // Are there enough remaining elements to be selected?
    // This test isn't required for the function to be correct, but
    // it can save a good amount of futile function calls.
    if ((elems.size() - margin) < (req_len - depth))
        return;
    
    // Try to select new elements to the right of the last selected one.
    for (unsigned long ii = margin; ii < elems.size(); ++ii) {
        pos[depth] = ii;
        combinations_recursive(elems, req_len, pos, depth + 1, ii + 1);
    }
    return;
}

void combinations(const vector<data> &elems, unsigned long req_len)
{
    assert(req_len > 0 && req_len <= elems.size());
    vector<unsigned long> positions(req_len, 0);
    combinations_recursive(elems, req_len, positions, 0, 0);
}

int main(void)
{
    ios::sync_with_stdio(false);
    
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    int N,M;
    cin >> N >> M;
    
    vector<data> input(N);
    
    
    for (int i=0;i<N;i++)
    {
        cin >> input[i].b >> input[i].t >> input[i].p;
    }
    
    combinations(input, M);

    printf("%lld",ans);
}





Compiler output:
a.cc:18:46: error: template argument 1 is invalid
   18 | void combinations_recursive(const vector<data> &elems, unsigned long req_len,
      |                                              ^
a.cc:18:46: error: template argument 2 is invalid
a.cc:18:46: error: template argument 1 is invalid
a.cc:18:46: error: template argument 2 is invalid
a.cc:18:46: error: template argument 1 is invalid
a.cc:18:46: error: template argument 2 is invalid
a.cc:18:35: error: invalid template-id
   18 | void combinations_recursive(const vector<data> &elems, unsigned long req_len,
      |                                   ^~~~~~
a.cc:18:6: error: variable or field 'combinations_recursive' declared void
   18 | void combinations_recursive(const vector<data> &elems, unsigned long req_len,
      |      ^~~~~~~~~~~~~~~~~~~~~~
a.cc:18:29: error: expected primary-expression before 'const'
   18 | void combinations_recursive(const vector<data> &elems, unsigned long req_len,
      |                             ^~~~~
a.cc:18:56: error: expected primary-expression before 'unsigned'
   18 | void combinations_recursive(const vector<data> &elems, unsigned long req_len,
      |                                                        ^~~~~~~~
a.cc:19:51: error: expected primary-expression before '&' token
   19 |                             vector<unsigned long> &pos, unsigned long depth,
      |                                                   ^
a.cc:19:52: error: 'pos' was not declared in this scope; did you mean 'pow'?
   19 |                             vector<unsigned long> &pos, unsigned long depth,
      |                                                    ^~~
      |                                                    pow
a.cc:19:57: error: expected primary-expression before 'unsigned'
   19 |                             vector<unsigned long> &pos, unsigned long depth,
      |                                                         ^~~~~~~~
a.cc:20:29: error: expected primary-expression before 'unsigned'
   20 |                             unsigned long margin)
      |                             ^~~~~~~~
a.cc:53:36: error: template argument 1 is invalid
   53 | void combinations(const vector<data> &elems, unsigned long req_len)
      |                                    ^
a.cc:53:36: error: template argument 2 is invalid
a.cc:53:36: error: template argument 1 is invalid
a.cc:53:36: error: template argument 2 is invalid
a.cc:53:36: error: template argument 1 is invalid
a.cc:53:36: error: template argument 2 is invalid
a.cc:53:25: error: invalid template-id
   53 | void combinations(const vector<data> &elems, unsigned long req_len)
      |                         ^~~~~~
a.cc:53:6: error: variable or field 'combinations' declared void
   53 | void combinations(const vector<data> &elems, unsigned long req_len)
      |      ^~~~~~~~~~~~
a.cc:53:19: error: expected primary-expression before 'const'
   53 | void combinations(const vector<data> &elems, unsigned long req_len)
      |                   ^~~~~
a.cc:53:46: error: expected primary-expression before 'unsigned'
   53 | void combinations(const vector<data> &elems, unsigned long req_len)
      |                                              ^~~~~~~~
a.cc: In function 'int main()':
a.cc:70:16: error: template argument 1 is invalid
   70 |     vector<data> input(N);
      |                ^
a.cc:70:16: error: template argument 2 is invalid
a.cc:75:21: error: invalid types 'int[int]' for array subscript
   75 |         cin >> input[i].b >> input[i].t >> input[i].p;
      |                     ^
a.cc:75:35: error: invalid types 'int[int]' for array subscript
   75 |         cin >> input[i].b >> input[i].t >> input[i].p;
      |                                   ^
a.cc:75:49: error: invalid types 'int[int]' for array subscript
   75 |         cin >> input[i].b >> input[i].t >> input[i].p;
      |                                                 ^
a.cc:78:5: error: 'combinations' was not declared in this scope
   78 |     combinations(input, M);
      |     ^~~~~~~~~~~~