C++ Easy Solution || Best Approach ||✅✅
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```\nclass Solution {\n    long long sqr(long long x) {\n        return x * x;\n    }\n\npublic:\n    long long findMaximumElegance(vector<vector<int>>& items, int k) {\n        const int n = items.size();\n        vector<int> ind(n);\n        for (int i = 0; i < n; ++i) {\n            ind[i] = i;\n        }\n        sort(ind.begin(), ind.end(), [&](const int x, const int y) {\n            return items[x][0] > items[y][0];\n        });\n        unordered_map<int, int> num;\n        priority_queue<pair<int, int>> q;\n        long long v = 0;\n        for (int i = 0; i < k; ++i) {\n            v += items[ind[i]][0];\n            ++num[items[ind[i]][1]];\n            q.push({-items[ind[i]][0], ind[i]});\n        }\n        long long r = v + sqr(num.size());\n        for (int i = k; i < n && !q.empty(); ++i) {\n            if (num.count(items[ind[i]][1])) {\n                continue;\n            }\n            const int x = q.top().second;\n            q.pop();\n            if (num[items[x][1]] == 1) {\n                --i;\n                continue;\n            }\n            v += items[ind[i]][0] - items[x][0];\n            --num[items[x][1]];\n            ++num[items[ind[i]][1]];\n            r = max(r, v + sqr(num.size()));  // calling function\n        }\n        return r;\n    }\n};\n```
['C++']