✅ Java Solution | Easy to understand
CODE\nJava []\npublic long maximumHappinessSum(int[] happiness, int k) {\n\tArrays.sort(happiness);\n\n\tint turn = k, n=happiness.length, i=n-1;\n\tlong res=0;
## **CODE**\n```Java []\npublic long maximumHappinessSum(int[] happiness, int k) {\n\tArrays.sort(happiness);\n\n\tint turn = k, n=happiness.length, i=n-1;\n\tlong res=0;\n\twhile(i>=0 && turn > 0){\n\t\tif(k-turn >= happiness[i]) break;\n\n\t\tres += happiness[i--];\n\t\tres -= (k-turn);\n\t\tturn--;\n\t}\n\treturn res;\n}\n```
['Sorting', 'Java']