cum

 avatar
unknown
c_cpp
5 months ago
684 B
3
Indexable
#include <bits/stdc++.h>
using namespace std;

struct Point
{
    int x, y;
};

void solve()
{
    int n;
    cin >> n;

    vector<Point> v(n);

    for (int i = 0; i < n; i++)
    {
        cin >> v[i].x >> v[i].y;
    }

    sort(v.begin(), v.end(), [](Point &a, Point &b)
         {
        int inv = 0;

        inv += a.x > b.x;
        inv += a.x > b.y;
        inv += a.y > b.x;
        inv += a.y > b.y;

        return inv < 2; });

    for (auto p : v)
    {
        cout << p.x << " " << p.y << " ";
    }
    cout << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}
Editor is loading...
Leave a Comment