Easy Solution | | Using C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define ll long long\nclass Solution {\npublic:\n    long long findMaximumElegance(vector<vector<int>>& items, int k) {\n        sort(items.rbegin(),items.rend());\n        ll n=items.size(),temp=0,ans=0;\n        unordered_map<int,int> m;\n        for(int i=0;i<k;i++){\n        m[items[i][1]]++;\n        temp+=items[i][0];\n        }\n        ll size=m.size(),left=k-1;\n        ans=max(ans,temp+(size*size));\n        for(int i=k;i<n;i++){\n            if(m.count(items[i][1])==0){\n                while(left>=0){\n                    if(m[items[left][1]]>1){\n                        m[items[left][1]]--;\n                        m[items[i][1]]++;\n                        temp-=items[left][0];\n                        temp+=items[i][0];\n                        ll o=m.size();\n                        ans=max(ans,temp+(o*o));\n                        left--;\n                        break;\n                    }\n                    left--;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']