Simple and Short | Sorting/Heap | 2 Solutions
\nclass Solution {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        Arrays.sort(happiness);\n        long ans = 0;\n        int minus = 0
```\nclass Solution {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        Arrays.sort(happiness);\n        long ans = 0;\n        int minus = 0;\n        int i = happiness.length - 1;\n        while(minus < k){\n            ans += Math.max(happiness[i] - minus, 0);\n            minus++;\n            i--;\n        }\n        return ans;\n    }\n}\n```\n---\n```\nclass Solution {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        PriorityQueue<Integer> heap = new PriorityQueue<>();\n        \n        for(int happy : happiness){\n            heap.add(happy);\n            if(heap.size() > k)\n                heap.poll();\n        }\n        long ans = 0;\n        while(k > 0){\n            ans += Math.max(heap.poll() - (k-1), 0);\n            k--;\n        }\n        return ans;\n    }\n}\n\n
['Sorting', 'Heap (Priority Queue)', 'Java']