Swift solution
Complexity\n- Time complexity: O(n * log(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n)
# Complexity\n- Time complexity: $$O(n * log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    func maximumHappinessSum(_ happiness: [Int], _ k: Int) -> Int {\n        let hapiness = happiness.sorted(by: >)\n        var result = 0\n        for i in 0 ..< min(hapiness.count, k) {\n            let subRes = hapiness[i] - i\n            if subRes <= .zero {\n                break\n            }\n            result += subRes\n        }\n        return result\n    }\n}\n```
['Array', 'Greedy', 'Swift', 'Sorting']