|
| 1 | +<p>A magician has various spells.</p> |
| 2 | + |
| 3 | +<p>You are given an array <code>power</code>, where each element represents the damage of a spell. Multiple spells can have the same damage value.</p> |
| 4 | + |
| 5 | +<p>It is a known fact that if a magician decides to cast a spell with a damage of <code>power[i]</code>, they <strong>cannot</strong> cast any spell with a damage of <code>power[i] - 2</code>, <code>power[i] - 1</code>, <code>power[i] + 1</code>, or <code>power[i] + 2</code>.</p> |
| 6 | + |
| 7 | +<p>Each spell can be cast <strong>only once</strong>.</p> |
| 8 | + |
| 9 | +<p>Return the <strong>maximum</strong> possible <em>total damage</em> that a magician can cast.</p> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<div class="example-block"> |
| 15 | +<p><strong>Input:</strong> <span class="example-io">power = [1,1,3,4]</span></p> |
| 16 | + |
| 17 | +<p><strong>Output:</strong> <span class="example-io">6</span></p> |
| 18 | + |
| 19 | +<p><strong>Explanation:</strong></p> |
| 20 | + |
| 21 | +<p>The maximum possible damage of 6 is produced by casting spells 0, 1, 3 with damage 1, 1, 4.</p> |
| 22 | +</div> |
| 23 | + |
| 24 | +<p><strong class="example">Example 2:</strong></p> |
| 25 | + |
| 26 | +<div class="example-block"> |
| 27 | +<p><strong>Input:</strong> <span class="example-io">power = [7,1,6,6]</span></p> |
| 28 | + |
| 29 | +<p><strong>Output:</strong> <span class="example-io">13</span></p> |
| 30 | + |
| 31 | +<p><strong>Explanation:</strong></p> |
| 32 | + |
| 33 | +<p>The maximum possible damage of 13 is produced by casting spells 1, 2, 3 with damage 1, 6, 6.</p> |
| 34 | +</div> |
| 35 | + |
| 36 | +<p> </p> |
| 37 | +<p><strong>Constraints:</strong></p> |
| 38 | + |
| 39 | +<ul> |
| 40 | + <li><code>1 <= power.length <= 10<sup>5</sup></code></li> |
| 41 | + <li><code>1 <= power[i] <= 10<sup>9</sup></code></li> |
| 42 | +</ul> |
0 commit comments