Priority Queue | Greedy | Easy Explaination | C++
Intitution\nsort the rides vector according to first day \nfor each day remove the rides that are ending on that day and take the maximum of the earning you are
**Intitution**\nsort the rides vector according to first day \nfor each day remove the rides that are ending on that day and take the maximum of the earning you are making till that day\nAlso each day see which rides are starting and push them in the min-priority-queue such that ride with smallest end day comes first and add the maximum earnings that can be made till that day so that any ride starting that day will have maximum earning they can have considering all the days before\nreturn the maximum earning\n\n```\nclass Solution {\npublic:\n    long long maxTaxiEarnings(int n, vector<vector<int>>& rides) {\n        priority_queue<pair<int64_t,int64_t>,vector<pair<int64_t,int64_t>>,greater<pair<int64_t,int64_t>>>pq;\n        int64_t ind = 0,mx = 0;\n        int64_t N = (int64_t)rides.size();\n        sort(rides.begin(),rides.end());\n        for(int64_t i = 1; i<= n; i++){\n            while(!pq.empty() && pq.top().first <= i){\n                mx = max(mx,pq.top().second);\n                pq.pop();\n            }\n            while(ind < N && rides[ind][0] == i){\n                pq.push({rides[ind][1],rides[ind][1]-rides[ind][0]+rides[ind][2]+mx});\n                ind++;\n            }\n        }\n        return mx;\n    }\n};\n```
['Greedy', 'C', 'Heap (Priority Queue)']