heap sort||basic c++code
\n\n# Code\n\nclass Solution {\npublic:\n      long long maximumHappinessSum(std::vector<int>& happiness, int k) {\n        std::sort(happiness.begin(), happine
\n\n# Code\n```\nclass Solution {\npublic:\n      long long maximumHappinessSum(std::vector<int>& happiness, int k) {\n        std::sort(happiness.begin(), happiness.end(), std::greater<int>());\n\n        std::vector<bool> selected(happiness.size(), false);\n\n        long long ans = 0;\n        int count = 0;\n\n        for (int i = 0; i < happiness.size(); ++i) {\n            if (!selected[i]) {\n                ans += std::max(0, happiness[i] - count);\n                ++count;\n                selected[i] = true;\n\n                if (count >= k) {\n                    break;\n                }\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']