Greedy Solution || C++
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n*log(n))\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n)\
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n*log(n))$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```\nclass Solution {\npublic:\n    long long findMaximumElegance(vector<vector<int>>& items, int k) {\n        sort(items.begin(),items.end());\n        reverse(items.begin(),items.end());\n        long long sum=0;\n        priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;\n        map<int,int> mp;\n        for(int i=0;i<k;i++)\n        {   \n            sum+=items[i][0];\n            mp[items[i][1]]++;\n            pq.push({items[i][0],items[i][1]});\n        }\n        long long maxi=sum+pow(mp.size(),2);\n        int index=k;\n        while(!pq.empty()&&index<items.size())\n        {\n            if(mp[items[index][1]]==0)\n            {\n                int mini=pq.top().first;\n                int s=pq.top().second;\n                pq.pop();\n                if(mp[s]>1)\n                {\n                    mp[s]--;\n                    sum=sum-mini+items[index][0];\n                    maxi=max(maxi,(long long)(sum+pow(mp.size(),2)));\n                    mp[items[index][1]]++;\n                    index++;\n                }\n            }\n            else\n            {\n                index++;\n            }\n        }\n        return maxi;\n    }\n};\n```
['C++']