Easy to understand c++
Intuition\n Describe your first thoughts on how to solve this problem. \nfirst maximum then max no of distinct catagory.\n\n# Approach\n Describe your approach 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nfirst maximum then max no of distinct catagory.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.first calculate k max profitable item.and if duplicate catagory found store it in a vector;\n\n2.then traverse if catagory not found then calculate elegance with new profit and after substracting, pop-back() duplicate vector .\n3.if catagory found then countinue because you have already max ele.\n4.if duplicate vector empty return the answer\n   \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(NlogN)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(k)\n\n# Code\n```\n  bool cmp(vector<int>&a,vector<int>&b){\n    return a[0]>b[0];\n  }\nclass Solution {\npublic:\n    long long findMaximumElegance(vector<vector<int>>& items, int k) {\n        sort(items.begin(),items.end(),cmp);\n        int n=items.size();\n        vector<int>dup;\n        set<int>s;\n        long long totalpro=0;\n        for(int i=0;i<k;i++){\n            totalpro+=items[i][0];\n            if(s.find(items[i][1])!=s.end()) dup.push_back(items[i][0]);\n             s.insert(items[i][1]);\n           }\n         long long ele=totalpro+(s.size()*s.size());\n         for(int i=k;i<n;i++){\n            if(s.find(items[i][1])!=s.end()) continue;\n            else{\n                if(!dup.size()) break;\n                totalpro-=dup[dup.size()-1];\n                dup.pop_back();\n                totalpro+=items[i][0];\n                s.insert(items[i][1]);\n                long long curr=totalpro+(s.size()*s.size());\n                ele=max(ele,curr);\n             }\n          } \n          return ele; \n    }\n};\n```
['C++']