Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<queue>
- #include<algorithm>
- using namespace std;
- struct COMPA{
- bool operator()(pair<long,pair<long,long>> &a, pair<long,pair<long,long>> &b){
- if(a.first!=b.first){
- return a.first<b.first;
- }
- return a.second.first > b.second.first;
- }
- };
- int main(){
- priority_queue<pair<long, pair<long, long>>, vector<pair<long, pair<long, long>>>, COMPA> q;
- q.push({3,{1,4}});
- q.push({4,{2,6}});
- q.push({4,{3,7}});
- q.push({3,{2,5}});
- q.push({1,{2,3}});
- int x = 1;
- while(!q.empty()){
- pair<long, pair<long, long>> p = q.top();
- q.pop();
- long l = p.second.first, r = p.second.second;
- cout<<p.first<<" "<<l<<" "<<r<<" "<<endl;
- }
- cout<<endl<<"------------------"<<endl;
- vector<pair<long, pair<long, long>>> v;
- v.push_back({3,{1,4}});
- v.push_back({4,{2,6}});
- v.push_back({4, {3, 7}});
- v.push_back({3, {2, 5}});
- v.push_back({1, {2, 3}});
- sort(v.begin(), v.end(), COMPA());
- for(auto &x: v){
- cout<<x.first<<" "<<x.second.first<<" "<<x.second.second<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment