Loading...
Loading...
Loading...
A game board has numbers. Choosing a number v earns v points for each copy of v on the board, but it also removes every copy of v - 1 and v + 1, so those can never be chosen. A value can be chosen at most once. Print the largest total score.
Example 1
Input
3 4 2
Output
6
Choose 2 and 4 for 6 points.
Example 2
Input
2 2 3 3 3 4
Output
9
Choose 3 three times for 9 points.
Try the problem first. Open one hint at a time.
Count each value, then the gain of value v is v times its count.
Walk through the sorted distinct values like house robber, where neighbours are values that differ by 1.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor