Just a runnable solution
\n\nimpl Solution {\n    pub fn find_maximum_elegance(items: Vec<Vec<i32>>, k: i32) -> i64 {\n        let mut items = items\n            .iter()\n            .m
\n```\nimpl Solution {\n    pub fn find_maximum_elegance(items: Vec<Vec<i32>>, k: i32) -> i64 {\n        let mut items = items\n            .iter()\n            .map(|v| v.iter().map(|&x| x as i64).collect::<Vec<_>>())\n            .collect::<Vec<_>>();\n        let k = k as usize;\n        items.sort_unstable_by(|a, b| b[0].cmp(&a[0]));\n        let mut vis = std::collections::HashSet::new();\n        let mut heap = std::collections::BinaryHeap::new();\n        let mut tot = 0;\n        for item in items.iter().take(k) {\n            if vis.contains(&item[1]) {\n                heap.push(std::cmp::Reverse(item[0]));\n            } else {\n                vis.insert(item[1]);\n            }\n            tot += item[0];\n        }\n        let mut ans = tot + vis.len() as i64 * vis.len() as i64;\n        for item in items.iter().skip(k) {\n            if !heap.is_empty() && !vis.contains(&item[1]) {\n                vis.insert(item[1]);\n                tot -= heap.pop().unwrap().0;\n                tot += item[0];\n                ans = ans.max(tot + vis.len() as i64 * vis.len() as i64);\n            }\n        }\n        ans\n    }\n}\n```
['Rust']