Beats 97% || EASY and straight to the point.
Intuition\n Describe your first thoughts on how to solve this problem. \n# UPVOTE PPL.\n# Approach\n Describe your approach to solving the problem. \n\n\n1. Sor
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n# UPVOTE PPL.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n1. **Sorting Happiness Scores:**\n   - `Arrays.sort(happiness)`: Sorts the `happiness` array in descending order. This ensures that people with higher happiness scores are considered first for seat assignments.\n\n2. **Initializing Variables:**\n   - `int count = 0`: Initializes a variable `count` to keep track of the number of seats assigned so far (out of `k`).\n   - `long ans = 0`: Initializes a variable `ans` to store the total happiness sum.\n\n3. **Iterating and Calculating Happiness:**\n   - `while (count != k)`: The loop iterates until `k` seats are assigned.\n     - `int value = happiness[happiness.length - 1 - count] - count`: This line calculates the happiness contribution for the current person being considered.\n       - `happiness[happiness.length - 1 - count]`: Accesses the happiness score of the person at the `count`th position from the end of the sorted `happiness` array (since it\'s sorted descendingly).\n       - `- count`: Subtracts the current seat number (`count`) from the happiness score. This penalty represents the unhappiness caused by not assigning a consecutive seat.\n     - `if (value > 0)`: Checks if the calculated happiness contribution (`value`) is positive.\n       - If positive (`value > 0`), it means there\'s still happiness to be gained by assigning this person a seat, even after considering the penalty.\n         - `ans += happiness[happiness.length - 1 - count] - count`: Adds the happiness contribution (`value`) to the total happiness sum (`ans`).\n     - `count++`: Increments the `count` to move on to the next person (considering the next seat).\n\n4. **Returning the Maximum Happiness Sum:**\n   - `return ans`: After iterating and assigning seats to `k` people, the function returns the final `ans`, which represents the maximum achievable happiness sum considering the happiness scores and seat assignment penalties.\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(NLOGN)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n```python []\nclass Solution:\n    def maximumHappinessSum(self, happiness, k):\n        happiness.sort()\n        count = 0\n        ans = 0\n        while count != k:\n            value = happiness[-1 - count] - count\n            if value > 0:\n                ans += happiness[-1 - count] - count\n            count += 1\n        return ans\n\n```\n\n\n# Code\n```\nclass Solution {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        Arrays.sort(happiness);\n        int count=0;\n        long ans=0;\n        while(count!=k){\n            int value=happiness[happiness.length-1-count]-count;\n            if(value>0){\n                ans+=happiness[happiness.length-1-count]-count;\n            }\n            count++;\n        }\n        return ans;\n    }\n}\n```
['Python', 'Java']