aj30

Untitled

May 14th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<queue>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7.  
  8. struct COMPA{
  9.     bool operator()(pair<long,pair<long,long>> &a, pair<long,pair<long,long>> &b){
  10.         if(a.first!=b.first){
  11.             return a.first<b.first;
  12.         }
  13.         return a.second.first > b.second.first;
  14.     }
  15. };
  16.  
  17. int main(){
  18.     priority_queue<pair<long, pair<long, long>>, vector<pair<long, pair<long, long>>>, COMPA> q;
  19.     q.push({3,{1,4}});
  20.     q.push({4,{2,6}});
  21.     q.push({4,{3,7}});
  22.     q.push({3,{2,5}});
  23.     q.push({1,{2,3}});
  24.     int x = 1;  
  25.     while(!q.empty()){
  26.         pair<long, pair<long, long>> p = q.top();
  27.         q.pop();
  28.         long l = p.second.first, r = p.second.second;
  29.         cout<<p.first<<" "<<l<<" "<<r<<" "<<endl;
  30.     }
  31.     cout<<endl<<"------------------"<<endl;
  32.     vector<pair<long, pair<long, long>>> v;
  33.  
  34.     v.push_back({3,{1,4}});
  35.     v.push_back({4,{2,6}});
  36.     v.push_back({4, {3, 7}});
  37.     v.push_back({3, {2, 5}});
  38.     v.push_back({1, {2, 3}});
  39.     sort(v.begin(), v.end(), COMPA());
  40.     for(auto &x: v){
  41.         cout<<x.first<<" "<<x.second.first<<" "<<x.second.second<<endl;
  42.     }
  43.    
  44.    
  45.     return 0;
  46. }
Add Comment
Please, Sign In to add comment