Subscribe Us

Responsive Advertisement

Advertisement

SORT2D - 2D-SORT SPOJ solution pair related

 problem : https://www.spoj.com/problems/SORT2D/


  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. template <class type1>
  7. #define ll long long int
  8. #define endl "\n"
  9. #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
  10. using ordered_multiset = tree <type1, null_type, less_equal <type1>, rb_tree_tag, tree_order_statistics_node_update>;
  11. //ordered_multiset <ll> kek;(declaration for multiorder set)
  12. // ordered_set o_set;(declaration)
  13. //kek.order_of_key(i);(strictly less then i for multi order set)
  14. //o_set.order_of_key(5) ;(strictly less then i for multi order set)
  15. #define yes cout << "YES\n"
  16. #define no cout << "NO\n"
  17. int main()
  18. {
  19. ios_base::sync_with_stdio(0);
  20. cin.tie(0);
  21. cout.tie(0);
  22. ll t;
  23. cin>>t;
  24.  
  25. while(t--)
  26. {
  27. ll n;
  28. cin>>n;
  29. vector<pair<ll,ll>>vp;
  30.  
  31. while(n--)
  32. {
  33. ll x,y;
  34. cin>>x>>y;
  35. vp.push_back({x,-y});
  36.  
  37. }
  38. sort(vp.begin(),vp.end());
  39. for(ll i=0;i<vp.size();i++)cout<<vp[i].first<<" "<<-1*vp[i].second<<endl;
  40. }
  41.  
  42. return 0;
  43. }

Post a Comment

0 Comments