Easy | Sorting | Just follow the steps of code | Generic Code | Beat 100% | Refer code |
\n\n# Code\n\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happ, int k) {\n\n        sort(happ.begin() , happ.end());\n\n        in
\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumHappinessSum(vector<int>& happ, int k) {\n\n        sort(happ.begin() , happ.end());\n\n        int times = 0;\n\n        int n = happ.size();\n        int index = n-1;\n        long long sum = 0;\n\n        for(int i = 1 ; i <= k ; i++)\n        {\n            int curr_val = happ[index] - times;\n\n            if(curr_val <= 0)\n            {\n                break;\n            }\n            else\n            {\n                sum += curr_val;\n            }\n\n            index--;\n            times++;\n        }\n\n        return sum;\n    }\n};\n```
['C++']