bhupixb

Comparator function for SET

Sep 3rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define f first
  4. #define s second
  5. typedef pair < int, int > p;
  6. #define A(v) v.begin(), v.end()
  7. class comp{
  8. public:
  9. bool operator ()(const p &a, const p &b) const{
  10. if(a.f == b.f)return a.s > b.s;
  11. if(a.f == 0)return 1;
  12. return 0;
  13. }
  14. };
  15. int main() {
  16. int n, i, l, r;
  17. cin >> n;
  18. multiset < p , comp> ss;
  19. for(int i = 0; i < n; i++){
  20. cin >> l >> r;
  21. ss.insert({l,r});
  22. }
  23. for(auto i : ss)cout << i.s << ' ';
  24. return 0;
  25. }
Add Comment
Please, Sign In to add comment