0% found this document useful (0 votes)
12 views2 pages

2D Sort

The document is a C++ program that reads pairs of long long integers, sorts them based on the first value and, in case of ties, by the second value in descending order. It utilizes various macros for bit manipulation and mathematical constants. The main function handles multiple test cases and outputs the sorted pairs.

Uploaded by

mo7amed3atf24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

2D Sort

The document is a C++ program that reads pairs of long long integers, sorts them based on the first value and, in case of ties, by the second value in descending order. It utilizes various macros for bit manipulation and mathematical constants. The main function handles multiple test cases and outputs the sorted pairs.

Uploaded by

mo7amed3atf24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<bits/stdc++.

h>
#define ATEF ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define dd double
#define pb push_back
#define ld long double
#define PQ priority_queue
#define pii pair<int,int>
#define pll pair<ll,ll>
#define S second
#define F first
#define MP make_pair
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define DIFF(x, y) ((x) > (y) ? (x) - (y) : (y) - (x))
#define INF 0x3f3f3f3f
#define NEG_INF (-INF)
// Define a macro to set a bit at position i in a number n
#define SET_BIT(n, i) ((n) |= (1 << (i)))
// Define a macro to clear a bit at position i in a number n
#define CLEAR_BIT(n, i) ((n) &= ~(1 << (i)))
// Define a macro to toggle a bit at position i in a number n
#define TOGGLE_BIT(n, i) ((n) ^= (1 << (i)))
// Define a macro to check if a bit at position i in a number n is set
#define IS_SET(n, i) ((n) & (1 << (i)))
#define SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#define IS_POWER_OF_TWO(n) ((n) && !((n) & ((n) - 1)))
#define IS_NAN(x) ((x) != (x))
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define endl "\n"
/*
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
*/
const int sz=1e6+1;
using namespace std;

bool comp(pair<ll,ll>&a,pair<ll,ll>&b)
{
if(a.F<b.F) return 1;
else if(a.F==b.F) return a.S>b.S;
return 0;
}
void solve(){
vector<pll> v;
int n;
scanf("%d", &n);
while (n--) {
ll l, r;
scanf("%lld %lld", &l, &r);
v.push_back(make_pair(l, r));
}
sort(v.begin(), v.end(), comp);
for (auto &it : v) {
printf("%lld %lld\n", it.first, it.second);
}
}

int main()
{
ATEF
int t=1;
scanf("%d",&t);
while(t--)
{
solve();
}

You might also like