Using Priority Queue And Map.....................................
Intuition\n Describe your first thoughts on how to solve this problem. \nfor maximum profit how you get?.. taking top k elemetns with higher profit no matter (t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nfor maximum profit how you get?.. taking top k elemetns with higher profit no matter (they belong to same category or not. think in greedy) after that choose that profit which is from differnt category so that our profit maximize so we can doing thish using min priority queue. first put top k elemetns in priority queue calculate res then iterate over n-k elements and choose that elemetn which from differnt category and remove that elem from queue which has less profit and number of count greater than 1.\n\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\nclass Solution {\npublic:\n    static bool compare(vector<int>&p1,vector<int>&p2){\n        return p1[0]>p2[0];\n    }\n    long long findMaximumElegance(vector<vector<int>>& items, int k) {\n        priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>>pq;\n        sort(items.begin(),items.end(),compare);\n        map<long long,long long>mp;\n        int n=items.size();\n        long long ans=0;\n        for(int i=0;i<k;i++){\n            ans+=items[i][0];\n            mp[items[i][1]]++;\n            pq.push({items[i][0],items[i][1]});\n        }\n        long long res=ans+(mp.size()*mp.size()*1ll);\n        int i=k;\n        while(i<n&&pq.size()!=0){\n            if(mp.count(items[i][1])){\n                i++;\n                continue;\n            }\n            auto it=pq.top();\n            pq.pop();\n            if(mp[it.second]==1){\n                continue;\n            }\n            ans+=items[i][0]-it.first;\n            --mp[it.second];\n            ++mp[items[i][1]];\n            res=max(res,ans+(long long)mp.size()*(long long)mp.size());\n            i++;\n        }\n        return res;\n    }\n};\n```
['C++']