Simple Sorting Solution!!⚡⚡🔥
\n\n# Code\n\nclass Solution {\npublic:\n    long long findMaximumElegance(vector<vector<int>>& items, int k) {\n        sort(items.begin(),items.end(),[&](vect
\n\n# Code\n```\nclass Solution {\npublic:\n    long long findMaximumElegance(vector<vector<int>>& items, int k) {\n        sort(items.begin(),items.end(),[&](vector<int>&a,vector<int>&b){\n           return a[0]>b[0];\n        });\n        unordered_set<int>s;\n        long long res=0;\n        long long ans=0;\n        vector<int>dup;\n        for(int i=0;i<items.size();i++){\n            if(i<k){\n                ans+=(items[i][0]);\n                if(s.count(items[i][1])){\n                  dup.push_back(items[i][0]);\n                }\n            }\n            else if(s.find(items[i][1])==s.end()){\n                if(dup.empty())break;\n                ans=ans-dup.back()+items[i][0];\n                dup.pop_back();\n            }\n            s.insert(items[i][1]);\n            long long v=ans+(s.size()*s.size());\n            res=max(res,v);\n        }\n        return res;\n\n    }\n};\n```
['C++']