Two Pointers
C++\ncpp    \nint maximizeGreatness(vector<int>& nums) {\n    int i = 0, sz = nums.size();\n    sort(begin(nums), end(nums));\n    for (int j = 0; j < sz; i += 
**C++**\n```cpp    \nint maximizeGreatness(vector<int>& nums) {\n    int i = 0, sz = nums.size();\n    sort(begin(nums), end(nums));\n    for (int j = 0; j < sz; i += (j++) < sz)\n        while (j < sz && nums[j] <= nums[i])\n            ++j;\n    return i;\n}\n```
[]