Need help for maximizing solution
This is a special case of maximum weighted independent set on an interval graph. Another way to phrase your problem is as follows: choose a subset of your neighbors of maximal sum in which no two elements have difference exactly 1.

One simple way to solve your problem is using dynamic programming. First sort the list, and remove duplicates (but remember how many of each number appear in the original list). Now use dynamic programming to calculate the optimal solution for every prefix of the sorted list.