```
class Solution {
public int deleteAndEarn(int[] nums) {
int[] dp = new int[10001];
for (int i : nums) {
dp[i]++;
}
for (int i = 2; i < dp.length; ++i) {
dp[i] = Math.max( dp[i-1], dp[i] * i + dp[i-2] );
}
return dp[10000];
}
}
```