C++ || Super Easy || Beats 100%
IntuitionThe problem requires maximizing the sum of happiness levels. Observing the input, the key insight is that the happiness levels are reduced linearly (by
# Intuition
The problem requires maximizing the sum of happiness levels. Observing the input, the key insight is that the happiness levels are reduced linearly (by their index). Sorting and then selecting the top k adjusted happiness values ensures the sum is maximized.

# Approach
1. Sort the happiness levels in descending order.

2. Subtract the index from each happiness value to account for the diminishing factor as per the problem's requirements.

3. Start from the largest adjusted happiness value and add them to the result until you reach the k limit or encounter a non-positive value.

# Complexity
- Time complexity:$$O(nlogn)$$

- Space complexity:$$O(1)$$

# Code
```cpp []
class Solution {
public:
    long long maximumHappinessSum(vector<int>& happiness, int k) {
        sort( happiness.begin(), happiness.end(), greater<int>() );
        for( int i = 0; i < happiness.size(); i++ )
            happiness[i] = happiness[i] - i;
        
        int i = 0;
        long long ans = 0;
        while( k && happiness[i] > 0 ){
            ans += happiness[i];
            k--;
            i++;
        }
        return ans;
    }
};
```
['C++']