Delete and Earn
Choosing value v earns v × (its count), but deletes every occurrence of v−1 and v+1 from the pool. Repeat until empty. Maximize the total earned.
Input: the first line has N; the second line has N positive integers.
Output: the maximum total.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ ai ≤ 104
Sample Tests
Input 1
3 3 4 2
Output 1
6
Input 2
5 2 2 3 3 3
Output 2
9
Discussion (opens after you solve — no spoilers before)
No comments yet.