Detailed Explanation😴|| Priority Queue + Greedy + Sort || O(n.logn) + O(k.logn)🔥
\n\n# Code\n\nclass Solution {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        int n = happiness.length;\n        long sum=0;\n        I
\n\n# Code\n```\nclass Solution {\n    public long maximumHappinessSum(int[] happiness, int k) {\n        int n = happiness.length;\n        long sum=0;\n        Integer [] happinessArray = new Integer[n];\n        for(int i = 0; i < n; i++) {\n            happinessArray[i] = happiness[i];\n        }\n        Arrays.sort(happinessArray,Collections.reverseOrder());\n        for(int i=0;i<k;i++){\n            if(happinessArray[i]-i<=0){\n                sum = sum + 0;\n            }\n            else { \n                sum = sum + happinessArray[i]-i;\n            }\n        }\n        return sum;\n    }\n}\n```
['Java']