✅ C#, Beginner Friendly, Beats %94 ✅
Intuition\n Describe your first thoughts on how to solve this problem. \nWe simply need to find n highest values inside the given array.\n\n# Approach\n Describ
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe simply need to find n highest values inside the given array.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst we sort the happiness list. In order to maximize our happiness score we start picking values from the end of the array. In order to satisfy the following line:\n\n"*n each turn, when you select a child, the happiness value of all the children that have not been selected till now decreases by 1. Note that the happiness value cannot become negative and gets decremented only if it is positive*."\n\n At each step of chosing a number, we decrement the picked value with respect to the #(count) of numbers picked. We take the Max value of 0 and pickedHappinessValue so that our happiness value doesn\'t go below 0 after decrementing it.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn) (Array.Sort function uses introsort with O(nlogn))\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```\npublic class Solution {\n    public long MaximumHappinessSum(int[] happiness, int k) {\n        if(happiness.Length<k) return -1; // handle edge-case\n        Array.Sort(happiness);\n        long sum=0;\n        for(int i=0;i<k;i++){\n            sum+=Math.Max(0,happiness[happiness.Length-1-i]-i);\n        }\n        return sum;\n    }\n}\n```
['Sorting', 'C#']