c++ solution
\nclass Solution {\npublic:\n    long long findMaximumElegance(vector<vector<int>>& item, int k) {\n        long long ans=0;\n        int size=item.size();\n   
```\nclass Solution {\npublic:\n    long long findMaximumElegance(vector<vector<int>>& item, int k) {\n        long long ans=0;\n        int size=item.size();\n        sort(item.begin(),item.end(),[&](auto &a,auto &b){return a[0]>b[0];});\n        unordered_set<int>seen;\n        vector<int>duplicateProfit;\n        long long profit=0;\n        int index=0;\n        for(auto &it:item)\n        {\n            int currentProfit=it[0];\n            int currentCategory=it[1];\n            if(index++<k){\n                if(seen.find(currentCategory)!=seen.end()){\n                    duplicateProfit.push_back(currentProfit);\n                }\n                profit+=currentProfit;\n            }\n            else if (seen.find(currentCategory)==seen.end()){\n                if(duplicateProfit.size()==0) return ans;\n                profit+=currentProfit-duplicateProfit.back();\n                duplicateProfit.pop_back();\n            }\n            seen.insert(currentCategory);\n            long long distint=seen.size()*seen.size();\n            ans=max(ans,profit+distint);\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']