[Python3] Sort by profit and use math
We can track everything in a single variable current and keep it updated by using the fact that (x^2) - ((x-1)^2) = 2x-1\n\npython\nclass Solution:\n    def fin
We can track everything in a single variable `current` and keep it updated by using the fact that (x^2) - ((x-1)^2) = 2x-1\n\n```python\nclass Solution:\n    def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n        best = current = 0\n        seen = set()\n        skipped = []\n        items.sort(reverse=True)\n        for price, category in items:\n            if category not in seen:\n                seen.add(category)\n                current += price + 2 * len(seen) - 1\n                if len(skipped) > k - len(seen):\n                    current -= skipped.pop()\n                if len(seen) == k:\n                    return max(best, current)\n            elif len(skipped) < k - len(seen):\n                current += price\n                skipped.append(price)\n            best = max(best, current)\n        return best\n```
[]