100% fastest || Greedy intutive approach complete explanation
our final goal is to find max profit out of all possible subsequence of k length\nso first thing comes in thought : let\'s sort in decreasing and return sum of 
our final goal is to find max profit out of all possible subsequence of k length\nso first thing comes in thought : let\'s sort in decreasing and return sum of first k elements and in normal condition that would be our best answer but here bcz of addtion of no of squire of unique elements we need to remove some of elemets which present multiple times bcz removing any multiple elements and adding a new unique one may increase our max profit \n\n// SOLUTION\n**first make a  multiset  with pair<int,int>   // profit  , catogery**\nwe will only push any element if it\'s count in map is more than one bcz we have sorted the array taking any unique element from start of the array is always goona make more profit as it\'s maximum by price and also adding a new element. and if any elemet occurs multiple time then it may be profitable to remove the lowest price element from the begining of the multi set to add a new unique element\n\n**a map <int, int> // catogery -> count**\nmap will simply keep track of no of unique elemets of array\n\n```\nUPVOTE IF U FIND HELPFUL\n```\n\n```\nclass Solution {\npublic:\n    long long findMaximumElegance(vector<vector<int>>&a, int k) \n    {\n        \n        multiset<pair<int,int>> ms;  // price, cat\n        map<int,int> m; // cat to count;\n        \n        sort(a.begin(),a.end(), greater<vector<int>>()); // Decreasing order\n        // for(auto i: a) cout<<i[0]<<" "<<i[1]<<endl;\n        long long ans=0;\n        long long s=0;\n        for(int i=0; i<k; i++)// take sum of first k elements\n        {\n            s+=a[i][0];\n            m[a[i][1]]++;\n            if(m[a[i][1]]>1)// if present multiple time\n            ms.insert({a[i][0],a[i][1]});\n            \n        }\n        \n        ans=s+m.size()*m.size();\n        int n=a.size();\n        for(int i=k; i<n; i++)\n        {\n            if(m.find(a[i][1])==m.end())// if not present in selection\n            {\n               \n                if(ms.size()) //  if their is any dublicate in selection\n                {\n\t\t\t\t\tauto it= ms.begin(); \n\t\t\t\t\tint c=it->second;\n\t\t\t\t\tint p=it->first;\n                    ms.erase(it);// remove the lowest price item\n                    s-=p;\n                    s+=a[i][0];\n                    m[c]--;  // update the frequency map\n                    if(m[c]==0) m.erase(c);\n                    m[a[i][1]]++;\n                    if(m[a[i][1]]>1) // won\'t ever happen but still just for logical condition for insertion in ms\n                    ms.insert({a[i][0],a[i][1]});\n\n                    ans= max(ans, s+(int)(m.size()*m.size())); // take max of all solutions\n                }\n            }\n        }\n        \n        return ans;\n        \n    }\n};\n\n```
['C', 'Sorting']