3075. Maximize Happiness of Selected Children

Photo by Ben Wicks on Unsplash

3075. Maximize Happiness of Selected Children

https://leetcode.com/problems/maximize-happiness-of-selected-children/description/

class Solution:
    def maximumHappinessSum(self, happiness: List[int], k: int) -> int:
        happiness.sort()
        happiness.reverse()

        ans = 0
        for i, e in enumerate(happiness[:k]):
            x = min(k, i, e)
            y = (e - x)
            ans += y

        return ans