Language: C++

#include <bits/stdc++.h>

using namespace std;

double calc_distance(vector<double> now) {
    return pow(pow(now[0], 2.0)+pow(now[1], 2.0), 0.5);
}

int main() {
    long n;
    cin >> n;
    vector<tuple<double,double,bool,bool,bool>> engin(n);
    for (long i = 0; i < n; ++i) {
        double x,y;
        cin >> x >> y;
        engin[i] = make_tuple(x, y, x>0, y>0, false);
    }

    //long max_j = -1;
    //vector<double> now = {0,0};
    //double max_dist = 0;
    //for (long i = 0; i < n; ++i) {
    //    for (long j = 0; j < n; ++j) {
    //        double x = get<0>(engin[j]);
    //        double y = get<1>(engin[j]);
    //        bool used = get<2>(engin[j]);
    //        if (!used) {
    //            vector<double> new_p = now;
    //            new_p[0] += x;
    //            new_p[1] += y;
    //            double new_d = calc_distance(new_p);
    //            if (max_dist < new_d) {
    //                max_j = j;
    //                max_dist = new_d;
    //            }
    //        }
    //    }
    //    if (max_j != -1) {
    //        now[0] += get<0>(engin[max_j]);
    //        now[1] += get<1>(engin[max_j]);
    //        get<2>(engin[max_j]) = true;
    //    }
    //    max_j = -1;
    //    max_dist = calc_distance(now);
    //}

    vector<double> plus_lim = {0,0};
    vector<double> minus_lim = {0,0};
    for (long i = 0; i < n; ++i) {
        double x = get<0>(engin[i]);
        double y = get<1>(engin[i]);
        bool x_p = get<2>(engin[i]);
        bool y_p = get<3>(engin[i]);
        if (x_p && y_p) {
            plus_lim[0] += x;
            plus_lim[1] += y;
        }
        if (!x_p && !y_p) {
            minus_lim[0] += x;
            minus_lim[1] += y;
        }
    }

    long max_p_j = -1;
    double max_p_dist = calc_distance(plus_lim);
    long max_n_j = -1;
    double max_n_dist = calc_distance(minus_lim);
    vector<tuple<double,double,bool,bool,bool>> p_engin = engin, n_engin = engin;
    for (long i = 0; i < n; ++i) {
        for (long j = 0; j < n; ++j) {
            double x_p = get<0>(p_engin[j]);
            double y_p = get<1>(p_engin[j]);
            bool x_p_p = get<2>(p_engin[j]);
            bool y_p_p = get<3>(p_engin[j]);
            bool used_p = get<4>(p_engin[j]);
            
            double x_n = get<0>(n_engin[j]);
            double y_n = get<1>(n_engin[j]);
            bool x_n_p = get<2>(n_engin[j]);
            bool y_n_p = get<3>(n_engin[j]);
            bool used_n = get<4>(n_engin[j]);

            if ((!x_p_p && y_p_p) || (x_p_p && !y_p_p)) {
                if (!used_p) {
                    vector<double> new_p_p = plus_lim;
                    new_p_p[0] += x_p;
                    new_p_p[1] += y_p;
                    double new_p_d = calc_distance(new_p_p);
                    if (max_p_dist < new_p_d) {
                        max_p_j = j;
                        max_p_dist = new_p_d;
                    }
                }
                if (!used_n) {
                    vector<double> new_n_p = minus_lim;
                    new_n_p[0] += x_n;
                    new_n_p[1] += y_n;
                    double new_n_d = calc_distance(new_n_p);
                    if (max_n_dist < new_n_d) {
                        max_n_j = j;
                        max_n_dist = new_n_d;
                    }
                }
            }
        }
        if (max_p_j != -1) {
            plus_lim[0] += get<0>(engin[max_p_j]);
            plus_lim[1] += get<1>(engin[max_p_j]);
            get<4>(engin[max_j]) = true;
        }
        max_p_j = -1;
        max_p_dist = calc_distance(plus_lim);
        if (max_n_j != -1) {
            minus_lim[0] += get<0>(engin[m])
        }
        max_n_j = -1;
        max_n_dist = calc_distance(minus_lim);
    }
    cout << fixed << setprecision(20) << max(calc_distance(plus_lim), calc_distance(minus_lim)) << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:109:26: error: 'max_j' was not declared in this scope; did you mean 'max_n_j'?
  109 |             get<4>(engin[max_j]) = true;
      |                          ^~~~~
      |                          max_n_j
a.cc:114:42: error: 'm' was not declared in this scope
  114 |             minus_lim[0] += get<0>(engin[m])
      |                                          ^