shelves: shelves[i] lists the prices of the items on shelf i, all positive integers.
Pick some items (at least one) so that:
- at most one item is taken from each shelf;
- all picked prices are pairwise different.
Return the largest possible sum of the picked prices.shelves=[[3, 7, 2], [7, 1, 4], [2, 2, 9]] → 20
Take 7 from the first shelf, 4 from the second (7 is already taken) and 9 from the third: 7 + 4 + 9 = 20.
shelves=[[5, 5], [5, 5]] → 5
Every shelf holds only 5s and a number cannot repeat, so only one item is taken: the answer is 5.
shelves=[[3, 7, 2], [7, 1, 4], [2, 2, 9]]
20
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.