Simple and straight forward solution, just sort and it's over, beats 94% :)
Intuition\nJust think of selecting the maximum element from the happiness array, in each iteration of k, until k becomes 0.\n\n# Approach\nFirst, we sort this l
# Intuition\nJust think of selecting the maximum element from the happiness array, in each iteration of k, until k becomes 0.\n\n# Approach\nFirst, we sort this list from lowest to highest happiness. Then, we start from the happiest person and gradually subtract a counter from their happiness, moving towards less happy people. We keep track of how much happiness we\'ve accumulated in a variable called \'happy\' and we will accumulate only if the happiness[i]-counter is positive so that no negative value gets accumulated. This continues until we\'ve made \'k\' iterations. Finally, we return the total accumulated happiness.\n\n# Complexity\n- Time complexity: O(nlogn) for sorting + O(k) for k turns \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happiness, int k) {\n        sort(happiness.begin(), happiness.end());\n        long long happy = 0;\n        long long counter = 0;\n        long long i = (happiness.size()-1);\n        while(k>0)\n        {   \n            //Ensuring that no negative value get accumulated\n            if(happiness[i]-counter > 0) \n                happy += (happiness[i] - counter);\n            i--;\n            counter++;\n            k--;\n        }\n        return happy;\n    }\n};\n```
['C++']