fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool cmp(pair<int,int> p1,pair<int,int> p2){
  5. if(p1.first!=p2.first){
  6. return p1.first<p2.first;
  7. }
  8. return p1.second>p2.second;
  9. }
  10. int main() {
  11. int t;
  12. scanf("%d",&t);
  13. while(t--){
  14. vector<pair<int,int>> v;
  15. int n;
  16. scanf("%d",&n);
  17. for(int i=0;i<n;i++){
  18. int x,y;
  19. scanf("%d%d",&x,&y);
  20. v.push_back(make_pair(x,y));
  21. }
  22. sort(v.begin(),v.end(),cmp);
  23. for(int i=0;i<n;i++){
  24. printf("%d %d\n",v[i].first,v[i].second);
  25. }
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 4200KB
stdin
1

5

3 4

-1 2

5 -3

3 3

-1 -2

stdout
-1 2
-1 -2
3 4
3 3
5 -3