C++ Solution | Priority_queue
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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#define ll long long\n\nclass Solution {\npublic:\n\n    static bool cmp(vector<int> &a, vector<int> &b) {return a[0]>b[0];}\n    \n    long long findMaximumElegance(vector<vector<int>>& items, int k) {\n        int n = items.size();\n\n        priority_queue<pair<ll,ll>> pq;\n        unordered_map<ll,ll> mp;\n        sort(items.begin(), items.end(), cmp);\n        ll sum = 0;\n        for(int i=0; i<k; i++){\n            sum += items[i][0];\n            pq.push({-items[i][0], i});\n            mp[items[i][1]]++;\n        }\n        ll res = sum + 1ll*mp.size()*mp.size();\n        int i=k;\n        while(i<n && !pq.empty()){\n            if(mp[items[i][1]]>0){\n                i++;\n                continue;\n            }\n            int curr = pq.top().second;\n            pq.pop();\n            if(mp[items[curr][1]]==1) continue;\n            sum += items[i][0]-items[curr][0];\n            mp[items[curr][1]]--;\n            mp[items[i][1]]++;\n            res = max(res, sum + (long long)mp.size()*(long long)mp.size());\n        }\n        return res;\n    }\n};\n```
['C++']