Language: C++

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<Int> P(a), Q(b), R(c);
    for (int i = 0; i < a; i++) {
        cin >> P[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> Q[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> R[i];
    }
    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());
    sort(R.begin(), R.end());

    vector<vector<Int>> re{P, Q, R}, gr{P, Q, R};
    Int red = 0, green = 0;
    for (int i = 0; i < x; i++) {
        if (!R.empty() && !P.empty()) {
            auto Pb = P.rbegin(), Rb = R.rbegin();
            if (*Pb < *Rb) {
                red += *Rb;
                R.pop_back();
            } else {
                red += *Pb;
                P.pop_back();
            }
        } else if (!R.empty()) {
            auto Rb = R.rbegin();
            red += *Rb;
        } else {
            auto Pb = P.rbegin();
            red += *Pb;
        }
    }
    for (int i = 0; i < y; i++) {
        if (!R.empty() && !P.empty()) {
            auto Qb = Q.rbegin(), Rb = R.rbegin();
            if (*Qb < *Rb) {
                red += *Rb;
                R.pop_back();
            } else {
                red += *Qb;
                Q.pop_back();
            }
        } else if (!R.empty()) {
            auto Rb = R.rbegin();
            red += *Rb;
        } else {
            auto Qb = Q.rbegin();
            red += *Qb;
        }
    }

    for (int i = 0; i < y; i++) {
        if (!R.empty() && !P.empty()) {
            auto Qb = Q.rbegin(), Rb = R.rbegin();
            if (*Qb < *Rb) {
                red += *Rb;
                R.pop_back();
            } else {
                red += *Qb;
                Q.pop_back();
            }
        } else if (!R.empty()) {
            auto Rb = R.rbegin();
            red += *Rb;
        } else {
            auto Qb = Q.rbegin();
            red += *Qb;
        }
    }
}
for (int i = 0; i < x; i++) {
    if (!R.empty() && !P.empty()) {
        auto Pb = P.rbegin(), Rb = R.rbegin();
        if (*Pb < *Rb) {
            green += *Rb;
            R.pop_back();
        } else {
            green += *Pb;
            P.pop_back();
        }
    } else if (!R.empty()) {
        auto Rb = R.rbegin();
        red += *Rb;
    } else {
        auto Pb = P.rbegin();
        red += *Pb;
    }
}
}

cout << max(red, green) << endl;

return 0;
}

Compiler output:
a.cc:88:1: error: expected unqualified-id before 'for'
   88 | for (int i = 0; i < x; i++) {
      | ^~~
a.cc:88:17: error: 'i' does not name a type
   88 | for (int i = 0; i < x; i++) {
      |                 ^
a.cc:88:24: error: 'i' does not name a type
   88 | for (int i = 0; i < x; i++) {
      |                        ^
a.cc:106:1: error: expected declaration before '}' token
  106 | }
      | ^
a.cc:108:1: error: 'cout' does not name a type
  108 | cout << max(red, green) << endl;
      | ^~~~
a.cc:110:1: error: expected unqualified-id before 'return'
  110 | return 0;
      | ^~~~~~
a.cc:111:1: error: expected declaration before '}' token
  111 | }
      | ^