Two pointer , C++
\n\n# Code\n\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        \n        sort(nums.begin(),nums.end());\n        int i=0,j=1,a
\n\n# Code\n```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        \n        sort(nums.begin(),nums.end());\n        int i=0,j=1,ans=0;\n        while(i<nums.size() && j<nums.size()){\n            if(nums[i]<nums[j]){\n                i++;j++;\n                ans++;\n            }\n            else{\n                j++;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']