Language: C++

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
 
int N, M;
long* X;
long* Y;
long* Z;
long LONG_MINI = -2147483648;
 
long saiki(int left, int start, long x, long y, long z){
    if(left == 0){
        return abs(x) + abs(y) + abs(z);
    }
    else if(N - start == left){
        for(int i = start; i < N; i ++){
            x += X[i];
            y += Y[i];
            z += Z[i];
        }
        return abs(x) + abs(y) + abs(z);
    }
    else{
        // eat
        long eat = saiki(left - 1, start + 1, x + X[start], y + Y[start], z + Z[start]);
        // not eat
        long notEat = saiki(left, start + 1, x, y, z);
        if(eat > notEat){
            return eat;
        }
        else{
            return notEat;
        }
    }
}
 
int main(){
 
    cin >> N >> M;
    X = new long[N];
    Y = new long[N];
    Z = new long[N];
    for(int i = 0; i < N; i ++){
        cin >> X[i] >> Y[i] >> Z[i];
    }
 
    long max = LONG_MINI;
 
 
    for(long x_fugou = -1; x_fugou < 2; x_fugou += 2){
        for(long y_fugou = -1; y_fugou < 2; y_fugou += 2){
            for(long z_fugou = -1; z_fugou < 2; z_fugou += 2){
                long result = 0;
                long* scores = new long[N];
                for(long i = 0; i < N; i ++){
                    scores[i] = X[i] * x_fugou + Y[i] * y_fugou + Z[i] * z_fugou;
                }
                sort(scores, scores+N);
                long finalScore = 0;
                for(long i = 0; i < M; i ++){
                    finalScore += scores[N - i - 1];
                }
                if(max < finalScore){
                    max = finalScore;
                }
            }
        }
    }
 
    //long result = saiki(M, 0, 0, 0, 0);
 
    cout << max << endl;  
    
    return 0;
}
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int N, M;
long* X;
long* Y;
long* Z;
long LONG_MINI = -2147483648;

long saiki(int left, int start, long x, long y, long z){
    if(left == 0){
        return abs(x) + abs(y) + abs(z);
    }
    else if(N - start == left){
        for(int i = start; i < N; i ++){
            x += X[i];
            y += Y[i];
            z += Z[i];
        }
        return abs(x) + abs(y) + abs(z);
    }
    else{
        // eat
        long eat = saiki(left - 1, start + 1, x + X[start], y + Y[start], z + Z[start]);
        // not eat
        long notEat = saiki(left, start + 1, x, y, z);
        if(eat > notEat){
            return eat;
        }
        else{
            return notEat;
        }
    }
}

int main(){

    
    long N, M, D;
    cin >> N >> M >> D;
    if(D == 0){
        double result = (M - 1) / N;
        cout << result << endl;
    }
    else {
        double result = 2 * (N - D) / N / N * (M - 1);
        cout << result << endl;
    }
    return 0;
}


Compiler output:
a.cc:82:5: error: redefinition of 'int N'
   82 | int N, M;
      |     ^
a.cc:6:5: note: 'int N' previously declared here
    6 | int N, M;
      |     ^
a.cc:82:8: error: redefinition of 'int M'
   82 | int N, M;
      |        ^
a.cc:6:8: note: 'int M' previously declared here
    6 | int N, M;
      |        ^
a.cc:83:7: error: redefinition of 'long int* X'
   83 | long* X;
      |       ^
a.cc:7:7: note: 'long int* X' previously declared here
    7 | long* X;
      |       ^
a.cc:84:7: error: redefinition of 'long int* Y'
   84 | long* Y;
      |       ^
a.cc:8:7: note: 'long int* Y' previously declared here
    8 | long* Y;
      |       ^
a.cc:85:7: error: redefinition of 'long int* Z'
   85 | long* Z;
      |       ^
a.cc:9:7: note: 'long int* Z' previously declared here
    9 | long* Z;
      |       ^
a.cc:86:6: error: redefinition of 'long int LONG_MINI'
   86 | long LONG_MINI = -2147483648;
      |      ^~~~~~~~~
a.cc:10:6: note: 'long int LONG_MINI' previously defined here
   10 | long LONG_MINI = -2147483648;
      |      ^~~~~~~~~
a.cc:88:6: error: redefinition of 'long int saiki(int, int, long int, long int, long int)'
   88 | long saiki(int left, int start, long x, long y, long z){
      |      ^~~~~
a.cc:12:6: note: 'long int saiki(int, int, long int, long int, long int)' previously defined here
   12 | long saiki(int left, int start, long x, long y, long z){
      |      ^~~~~
a.cc:114:5: error: redefinition of 'int main()'
  114 | int main(){
      |     ^~~~
a.cc:38:5: note: 'int main()' previously defined here
   38 | int main(){
      |     ^~~~