goods, where goods[i] = [profit, category] is an item's profit and its category. Exactly count items must go on display (each item from the list can be used at most once).
The value of a display is the total profit of the chosen items plus the **square** of the number of distinct categories among them.
Return the largest possible value of a display.goods=[[7, 1], [6, 1], [2, 2]], count=2 → 14
The two category-1 items give 7 + 6 + 1² = 14; items [7, 1] and [2, 2] give 7 + 2 + 2² = 13. So 14 is the best.
goods=[[10, 3], [9, 3], [1, 1], [1, 2]], count=3 → 24
Taking [10, 3], [9, 3] and [1, 1] gives profit 20 with two categories: 20 + 2² = 24, while three distinct categories reach only 10 + 1 + 1 + 3² = 21.
goods=[[5, 1]], count=1 → 6
goods=[[7, 1], [6, 1], [2, 2]], count=2
14
Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.