๐งโโ๏ธ A powerful magician has a spellbook filled with various magical spells, each dealing a specific amount of damage. You are given an array power where each element represents the damage value of a spell. Multiple spells can have the same damage value.
However, there's a crucial magical constraint: if a magician casts a spell with damage power[i], the magical interference prevents them from casting any spell with damage values power[i] - 2, power[i] - 1, power[i] + 1, or power[i] + 2.
Each spell can only be cast once, and your goal is to determine the maximum possible total damage the magician can achieve by strategically selecting which spells to cast.
Example: If you have spells with damage [2, 3, 4, 9], you cannot cast both damage-2 and damage-4 spells together (since |2-4| โค 2), but you can cast damage-2 and damage-9 together.
Input & Output
Constraints
- 1 โค power.length โค 105
- 1 โค power[i] โค 109
- Each spell can be cast only once
- Multiple spells can have the same damage value