Using Sorting and Map || Easy C++ Solution
Code\n\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        map<int,int>mp;\n        int n = nums.size();\n        for(int i = 0;
# Code\n```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        map<int,int>mp;\n        int n = nums.size();\n        for(int i = 0; i<n; i++){\n            mp[nums[i]]++;\n        }\n        sort(nums.begin(), nums.end());\n        \n        int count = 0;\n        for(int i = 0; i<n; i++){\n            \n            for(auto it: mp){\n                // modifying it.second directly within the loop will not work as expected because it is a copy of the key-value pair, and changes to it won\'t affect the original map. To correctly modify the map\'s values, you should use mp[it.first]--\n                while(it.first > nums[i] && i<n && mp[it.first] > 0){\n\n                    count++;\n                    mp[it.first]--;\n                    \n                    i++;\n                }\n            }\n        }\n        return count;\n    }\n};\n```
['Ordered Map', 'Sorting', 'C++']