Kotlin - Greedy only 6 lines. Simple and Short
Code\n\nclass Solution {\n    fun maximumHappinessSum(happiness: IntArray, k: Int): Long {\n        happiness.sortDescending()\n        var result = 0L\n       
# Code\n```\nclass Solution {\n    fun maximumHappinessSum(happiness: IntArray, k: Int): Long {\n        happiness.sortDescending()\n        var result = 0L\n        for (i in 0 until k) {\n            if (happiness[i] > i) result += happiness[i] - i\n        }\n        return result\n    }\n}\n```
['Kotlin']