Easy and Efficient Approach
\n\n# Approach\nWe first sort the happiness vector in descending order\nand then consider the elements that give maximum happiness value.\n\n# Complexity\n- Tim
\n\n# Approach\nWe first sort the happiness vector in descending order\nand then consider the elements that give maximum happiness value.\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happiness, int k) {\n        sort(happiness.begin(),happiness.end());\n        int n = happiness.size();\n        int i = 0 ;\n        long long ans = 0 ;\n        while(i < k){\n            if(happiness[n-i-1]-i >= 0){\n                ans += happiness[n-i-1] - i ;\n            }\n            i++ ;\n        }\n        return ans ;\n    }\n};\n```
['C++']