💯✅🔥Easy Java Solution|| 34 ms ||≧◠‿◠≦✌
Intuition\n Describe your first thoughts on how to solve this problem. \nThe approach taken in the code aims to maximize the total happiness sum by iteratively 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe approach taken in the code aims to maximize the total happiness sum by iteratively reducing the happiness values of the highest elements in the sorted array. By subtracting a decreasing amount from each element, the code attempts to distribute the reductions in a way that maximizes the overall happiness sum.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe given code sorts the array of happiness values in ascending order. It then iterates over the sorted array from the end towards the beginning, adjusting each happiness value by subtracting a decreasing amount based on its position in the sorted array. The adjusted happiness values are summed up to calculate the maximum happiness sum achievable after applying the adjustments.\n# Complexity\n- Time complexity: O(n log n)\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 {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        Arrays.sort(happiness);\n        int n = happiness.length;\n        long res = 0;\n        \n        for (int i = n - 1; k > 0; i--) {\n            happiness[i] = Math.max(happiness[i] - (n - 1 - i), 0);\n            res += happiness[i];\n            k--;\n        }\n        \n        return res;\n    }\n}\n```\n![upvote.png](https://assets.leetcode.com/users/images/9a6559be-5a64-4b2a-aa25-e8e1790c306c_1715214812.2561486.png)\n
['Array', 'Greedy', 'Java']