Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Damage With Spell Casting

Try to solve the Maximum Total Damage With Spell Casting problem.

Statement

A magician has an array of spells called power, where power[i] represents the damage dealt by the spell at index ii.

If a spell with damage xx is cast, no spell with damage equal to x−2x - 2, x−1x - 1, x+1x + 1, or x+2x + 2 can be cast. Each spell in power can be cast at most once.

Return the maximum possible total damage the magician can deal.

Constraints:

  • 1≤1 \leq power.length ≤105\leq 10^5

  • 1≤1 \leq power[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Damage With Spell Casting

Try to solve the Maximum Total Damage With Spell Casting problem.

Statement

A magician has an array of spells called power, where power[i] represents the damage dealt by the spell at index ii.

If a spell with damage xx is cast, no spell with damage equal to x−2x - 2, x−1x - 1, x+1x + 1, or x+2x + 2 can be cast. Each spell in power can be cast at most once.

Return the maximum possible total damage the magician can deal.

Constraints:

  • 1≤1 \leq power.length ≤105\leq 10^5

  • 1≤1 \leq power[i] ≤109\leq 10^9