maximize-happiness-of-selected-children 🚀Hard to catch 💯Medium Solution🫡cpp
\n\n\n# Code\n\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& h, int k) {\n        sort(h.begin(),h.end());\n        long long int s
![WhatsApp Image 2024-04-29 at 00.03.36_47c07d92.jpg](https://assets.leetcode.com/users/images/47383c0c-479f-485b-b4f8-f0cea81032df_1715419678.039848.jpeg)\n\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& h, int k) {\n        sort(h.begin(),h.end());\n        long long int sum=0;\n        long long int l=0;\n        // int mini = h[0];\n        for(int i=h.size()-1,j=0;i>=0,j<k;i--,j++){\n            if(h[i]<l){\n                long long int add = 0;\n                l++;\n                sum = sum + add;\n            }\n            else{\n                long long int add = h[i]-l;\n                l++;\n                sum = sum + add;\n                // mini--;\n            }\n        }\n        return sum;\n    }\n};\n```\n\n![7495fea3-7639-48a4-8ad9-79dc9237db4e_1701793058.7524364.png](https://assets.leetcode.com/users/images/37bbe274-bd2d-4408-94a7-b616c88068e4_1715419694.1266012.png)\n
['C++']