Greedy Selection | C++ | Java
Intuition, approach, and complexity disucussed in video solution in detail.\nhttps://youtu.be/0VlhZFs0WLE\n# Code\nC++\n\nclass Solution {\npublic:\n    long lo
# Intuition, approach, and complexity disucussed in video solution in detail.\nhttps://youtu.be/0VlhZFs0WLE\n# Code\nC++\n```\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happiness, int k) {\n        sort(happiness.begin(), happiness.end());\n        long long dec = 0, hapSum = 0, indx = happiness.size()-1;\n        while(k-->0){\n            hapSum += max(0ll, happiness[indx--] - (dec++));\n        }\n        return hapSum;\n    }\n};\n```\nJava\n```\nclass Solution {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        Arrays.sort(happiness);\n        long dec = 0, hapSum = 0;\n        int indx = happiness.length-1;\n        while(k-->0){\n            hapSum += Math.max(0l, happiness[indx--] - (dec++));\n        }\n        return hapSum;\n    }\n}\n```
['Array', 'Greedy', 'Sorting', 'C++', 'Java']