👏😻🙈Beats 97.44% of users with Java🎉||✅ one line (for loop) code || 💯🔥💥
SCREENSHORT\n\n\n# Intuition\nWe need max happiness and after selecting one dec all by one ... Hence select the one and sec by dec 1 and so one. \n\n>It\'s too 
# SCREENSHORT\n![3075.png](https://assets.leetcode.com/users/images/663dfbc1-9795-4e6b-82f0-74ecb45e840c_1715232658.1573184.png)\n\n# Intuition\nWe need max happiness and after selecting one dec all by one ... Hence select the one and sec by dec 1 and so one. \n\n>It\'s too easy just follow the steps.\n---\n\n\n# Approach\nWe will add and check max of selected and 0 hence we\'ll get our ans.\n\n1. ### Initialize variables Dec, Ans, n\n\n    ```\n        int dec = 0;\n        int n = happiness.length;\n        long ans = 0;\n    ```\n2. ### First **sort** the array \n\n    ```\n        Arrays.sort(happiness);\n    ```\n3. ### Apply a for loop in decrement order and upto **n - k**  \n \n    ```\n        for (int i = n - 1; i >= n - k; i--) {\n            //loop One line body\n        }\n    ```\n4. ### Write one line code here that is **max of happ[i] and 0** \n \n    ```\n        ans += Math.max(0, happiness[i] - dec); \n        dec++;      \n \n    ```\n    > Do not write dec++ in the same line it will dec our speed.\n\n    ```\n        // Do not write like this...\n        ans += Math.max(0, happiness[i] - dec++);   \n \n    ```\n5. ### Return res \uD83D\uDE01\uD83D\uDE01\n\n---\n\n\n# Complexity\n- Time complexity: $O(nlogn)$\n\n- Space complexity: $O(1)$\n\n---\n\n\n# Code\n```\nclass Solution {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        Arrays.sort(happiness);\n        int dec = 0;\n        int n = happiness.length;\n        long ans = 0;\n        for (int i = n - 1; i >= n - k; i--) {\n            ans += Math.max(0, happiness[i] - dec);\n            dec++;\n        }\n        return ans;\n    }\n}\n```
['Greedy', 'Sorting', 'Java']