class Solution//诡异的数据结构维护反悔贪心
{
public:long long findMaximumElegance(vector<vector<int>>& items, int k){sort(items.begin(), items.end(), [](const auto &a, const auto &b){return a[0] > b[0];});//奇妙的排序方法long long total_profit = 0 ,ans = 0;//最大利益与答案记录int length = items.size();unordered_set<int> vis;stack <int> same_element;//记录所有出现过两次的元素for(int i = 0;i < length;i++){if(i < k){total_profit+=items[i][0];if(!vis.insert(items[i][1]).second){same_element.push(items[i][0]);}}else if(!same_element.empty()&&vis.insert(items[i][1]).second){total_profit+=(items[i][0]-same_element.top());same_element.pop();}ans=max(ans,total_profit+(long long)pow(vis.size(),2));}return ans;}
};