Heap (Priority Queue) Greedy C++ solution easy approach to solve hard problem
Intuition\n Describe your first thoughts on how to solve this problem. \n# Approach\n Describe your approach to solving the problem. \nif casback is more don\'t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n# Approach\n<!-- Describe your approach to solving the problem. -->\nif casback is more don\'t take only take that at last moment i.e with maximum cost because you have to pay then only you are getting cashback other thing min heap\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(NlogN)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n# Code\n```\n\nclass Solution {\npublic:\n   long long int  max(long long int  a,long long int b){\n       if(a>b){\n           return a;\n       }\n       return b;\n   }\n\n    long long minimumMoney(vector<vector<int>>& tr) {\n        priority_queue<pair<long long int,long long int>,vector<pair<long long int,long long int>>,greater<pair<long long int,long long int>>>pq;\n   \n        long long k = 0;\n        for(int i = 0;i<tr.size();i++) {\n            if(tr[i][1]<=tr[i][0]){\n  pq.push({tr[i][1],tr[i][0]});\n            }\n          \n            else {\n                k = max(tr[i][0],k);\n            } \n        }\n        \n        long long int ans = 0;\n        long long int maxi = 0;\n       while(!pq.empty()) {\n            maxi = max(maxi,ans+pq.top().second);\n\n            ans = ans+(pq.top().second-pq.top().first);\n            pq.pop();\n         \n            \n        }\n        maxi = max(maxi,ans+k);\n        \n        return maxi;\n    }\n};\n```
['Greedy', 'Heap (Priority Queue)', 'C++']