[C++] 2 lines with std::partial_sort and std::accumulate
Intuition\nsort the k largest elements in decreasing order, then sum the values minus n with n starting at 0 and being incremented at each iteration of the sum.
# Intuition\nsort the k largest elements in decreasing order, then sum the values minus `n` with `n` starting at `0` and being incremented at each iteration of the sum.\n\n# Approach\nUse STL. Note that in order to save a line, I declared the variable `n` in the capture clause of the lambda, which requires the lambda to be non `const`. Lambdas being `const` by default, the keyword is `mutable`.\n\n\n# Complexity\n- Time complexity: $$O(n log(k))$$\n- Space complexity: $$O(1)$$\n\n\n# Code\n```cpp\nlong long maximumHappinessSum(vector<int>& happ, int k) {\n    partial_sort(happ.begin(), happ.begin()+k, happ.end(), greater<int>());\n    return accumulate(happ.begin(), happ.begin()+k, (long long)0, [n=0](long long a, int b)mutable{return a + max(0, b-n++);});\n}\n```
['C++']