[C++] Greedy with Simulation
Intuition\n Describe your first thoughts on how to solve this problem. \n- Greedy\n  - Select the k largest values in happiness\n- Simulation\n  - Simulate the 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Greedy\n  - Select the `k` largest values in `happiness`\n- Simulation\n  - Simulate the selection process\n  - Increase the `unhappy` value for each round\n  - Accumulate the sum by `max(0, happiness[i] - unhappy)` \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- sort the children by their happiness\n- greedy on happiness but decremented by the `unhappy`\n\n# Complexity\n- Time complexity: $$O(n\\times\\log{n})$$ for sorting\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(\\log{n})$$ for sorting\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    // time/space: O(nlogn)/O(logn)\n    long long maximumHappinessSum(vector<int>& happiness, int k) {\n        // sort the children by their happiness\n        sort(happiness.begin(), happiness.end(), greater<int>());\n        \n        // greedy on happiness but decremented by the `unhappy`\n        long long sum = 0LL;\n        for (int i = 0, unhappy = 0; i < k; i++, unhappy++) {\n            sum += max(0, happiness[i] - unhappy);\n        }\n        return sum;\n    }\n};\n```
['Greedy', 'Sorting', 'Simulation', 'C++']