🔥maxHeap - Beginner Friendly Code | Clean Code | C++ |
Code\n\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happiness, int k) {\n        priority_queue<int, vector<int>> maxHeap;\n      
# Code\n```\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happiness, int k) {\n        priority_queue<int, vector<int>> maxHeap;\n        for (auto x: happiness)\n        {\n            maxHeap.push(x);\n        }\n\n        long long decr = 0;\n        long long res = 0;\n        while (!maxHeap.empty() && k--)\n        {\n            int curr = maxHeap.top();\n            maxHeap.pop();\n\n            if (curr - decr > 0)\n            {\n                res += curr - decr;\n            }\n            else\n            {\n                break;\n            }\n\n            decr++;\n        }\n\n        return res;\n    }\n};\n```
['C++']