Language: C++

#include <bits/stdc++.h>

using namespace std;

//#define errOut(s) { std::cerr << "LINE:" << __LINE__ << " " << #s << " = " << s << std::endl; }
//#define errOut(s)

struct Point {
    int x;
    int y;
    std::vector<int> pairableIdxes;
    bool fixed;

    const bool operator<(const Point &another) const {
        return x + y < another.x + another.y;
    }
};

std::array<Point, 100> reds;
std::array<Point, 100> blues;

std::vector<int> soloRedIdxes;

int optimizePair(int begin, int threshold) {
    if (begin == soloRedIdxes.size()) {
        return 0;
    }
    if (soloRedIdxes.size() - begin < threshold) {
        cerr << "cut" << endl;
        return 0;
    }
    int ret = 0;
    auto &red = reds[soloRedIdxes[begin]];
    int numberOfTry = 0;
    for (int i = 0; i < red.pairableIdxes.size(); ++i) {
        auto &blue = blues[red.pairableIdxes[i]];
        if (blue.fixed) {
            continue;
        }
        ++ numberOfTry;
        blue.fixed = true;
        int candidate = optimizePair(begin + 1, std::max(threshold - 1, ret)) + 1;
        blue.fixed = false;
        ret = std::max(ret, candidate);
        if (ret == soloRedIdxes.size() - begin) {
            return ret;
        }
    }
    if (numberOfTry != 1) {
        int candidate = optimizePair(begin + 1, threshold);
        ret = std::max(ret, candidate);
    }
    return ret;
}

bool canPair(const Point &red, const Point &blue) {
    return red.x < blue.x && red.y < blue.y;
}

int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        auto &red = reds[i];
        std::cin >> red.x >> red.y;
        red.fixed = false;
    }
    for (int i = 0; i < n; ++i) {
        auto &blue = blues[i];
        std::cin >> blue.x >> blue.y;
        blue.fixed = false;
    }

    std::sort(reds.begin(), reds.begin() + n);
    std::sort(blues.begin(), blues.begin() + n);

    int ret = 0;
    int bound = 0;
    for (int i = 0; i < n; ++i) {
        auto &red = reds[i];
        bound = (int) (std::lower_bound(blues.begin() + bound, blues.begin() + n, red) - blues.begin());
        for (int j = bound; j < n; ++j) {
            auto &blue = blues[j];
            if (!canPair(red, blue)) {
                continue;
            }
            red.pairableIdxes.push_back(j);
            blue.pairableIdxes.push_back(i);
        }
    }

    for (int i = 0; i < n; ++i) {
        auto &red = reds[i];
        auto &blue = blues[i];
        if (red.pairableIdxes.size() == 0) {
            red.fixed = true;
        }
        if (blue.pairableIdxes.size() == 0) {
            blue.fixed = true;
        }
    }

    while (true) {
        bool anyFound = false;

        for (int i = 0; i < n; ++i) {
            auto &red = reds[i];
            if (red.fixed || red.pairableIdxes.size() != 1) {
                continue;
            }
            const auto blueIdx = red.pairableIdxes[0];
            auto &blue = blues[blueIdx];
            if (blue.fixed) {
                continue;
            }
            for (auto && anotherRedIdx : blue.pairableIdxes) {
                if (anotherRedIdx == i) {
                    continue;
                }
                auto &anotherRed = reds[anotherRedIdx];
                auto it = std::find(anotherRed.pairableIdxes.begin(), anotherRed.pairableIdxes.end(), blueIdx);
                if (it != anotherRed.pairableIdxes.end()) {
                    anotherRed.pairableIdxes.erase(it);
                }
            }
            red.fixed = true;
            blue.fixed = true;
            ++ret;
            anyFound = true;
        }
        for (int i = 0; i < n; ++i) {
            auto &blue = blues[i];
            if (blue.fixed || blue.pairableIdxes.size() != 1) {
                continue;
            }
            const auto redIdx = blue.pairableIdxes[0];
            auto &red = reds[redIdx];
            if (red.fixed) {
                continue;
            }
            for (auto &&anotherBlueIdx : red.pairableIdxes) {
                if (anotherBlueIdx == i) {
                    continue;
                }
                auto &anotherBlue = reds[anotherBlueIdx];
                auto it = std::find(anotherBlue.pairableIdxes.begin(), anotherBlue.pairableIdxes.end(), redIdx);
                if (it != anotherBlue.pairableIdxes.end()) {
                    anotherBlue.pairableIdxes.erase(it);
                }
            }
            red.fixed = true;
            blue.fixed = true;
            ++ret;
            anyFound = true;
        }

        if (!anyFound) {
            break;
        }
    }

    for (int i = 0; i < n; ++i) {
        const auto &red = reds[i];
        if (red.fixed) {
            continue;
        }
        soloRedIdxes.push_back(i);
    }
    if (soloRedIdxes.size() == 0) {
        std::cout << ret << std::endl;
        errOut(ret);
        return 0;
    }
    std::sort(soloRedIdxes.begin(), soloRedIdxes.end(), [&](const int &a, const int &b) {
        return reds[a].pairableIdxes.size() < reds[b].pairableIdxes.size();
    });
    errOut(ret);
    ret += optimizePair(0, 0);
    errOut(ret);
    std::cout << ret << std::endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:171:9: error: 'errOut' was not declared in this scope
  171 |         errOut(ret);
      |         ^~~~~~
a.cc:177:5: error: 'errOut' was not declared in this scope
  177 |     errOut(ret);
      |     ^~~~~~