O(k) Fast solution
\n\n# Approach\n Describe your approach to solving the problem. \nSort the array in descending order. After every pick from the array, all values in the array r
![image.png](https://assets.leetcode.com/users/images/3f3b9cfb-27f2-4dd1-b0be-d91f51e39f9e_1715227081.904867.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSort the array in descending order. After every pick from the array, all values in the array reduce by 1. So after n picks, total decrement in every value is n. \n\n# Complexity\n- Time complexity: O(k)\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        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);\n        sort(happiness.begin(), happiness.end(), greater<int>());\n        long long ans = 0;\n        int x = 0;\n        for (int i = 0; i < k; i++) {\n            x = happiness[i];\n            x = x - i;\n            if (x >= 0) {\n                ans += x;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']