1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/对 Bob 造成的最少伤害 [minimum-amount-of-damage-dealt-to-bob].html
2024-09-19 09:27:23 +08:00

62 lines
3.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数&nbsp;<code>power</code>&nbsp;和两个整数数组&nbsp;<code>damage</code>&nbsp;<code>health</code>&nbsp;,两个数组的长度都为&nbsp;<code>n</code>&nbsp;</p>
<p>Bob 有&nbsp;<code>n</code>&nbsp;个敌人,如果第&nbsp;<code>i</code>&nbsp;个敌人还活着(也就是健康值&nbsp;<code>health[i] &gt; 0</code>&nbsp;的时候),每秒钟会对 Bob 造成&nbsp;<code>damage[i]</code>&nbsp;<strong></strong>&nbsp;伤害。</p>
<p>每一秒中,在敌人对 Bob 造成伤害 <strong>之后</strong>&nbsp;Bob 会选择 <strong>一个</strong>&nbsp;还活着的敌人进行攻击,该敌人的健康值减少 <code>power</code>&nbsp;</p>
<p>请你返回 Bob 将 <strong>所有</strong>&nbsp;<code>n</code>&nbsp;个敌人都消灭之前,<strong>最少</strong>&nbsp;会收到多少伤害。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>power = 4, damage = [1,2,3,4], health = [4,5,6,8]</span></p>
<p><span class="example-io"><b>输出:</b>39</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>最开始 2 秒内都攻击敌人 3 ,然后敌人 3 会被消灭,这段时间内对 Bob 的总伤害是&nbsp;<code>10 + 10 = 20</code>&nbsp;点。</li>
<li>接下来 2 秒内都攻击敌人 2 ,然后敌人 2 会被消灭,这段时间内对 Bob 的总伤害是&nbsp;<code>6 + 6 = 12</code>&nbsp;点。</li>
<li>接下来 1 秒内都攻击敌人 0 ,然后敌人 0 会被消灭,这段时间内对 Bob 的总伤害是&nbsp;<code>3</code>&nbsp;点。</li>
<li>接下来 2 秒内都攻击敌人 1 ,然后敌人 1 会被消灭,这段时间内对 Bob 的总伤害是&nbsp;<code>2 + 2 = 4</code>&nbsp;点。</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>power = 1, damage = [1,1,1,1], health = [1,2,3,4]</span></p>
<p><span class="example-io"><b>输出:</b>20</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>最开始 1 秒内都攻击敌人 0 ,然后敌人 0 会被消灭,这段时间对 Bob 的总伤害是&nbsp;<code>4</code>&nbsp;点。</li>
<li>接下来 2 秒内都攻击敌人 1 ,然后敌人 1 会被消灭,这段时间对 Bob 的总伤害是&nbsp;<code>3 + 3 = 6</code>&nbsp;点。</li>
<li>接下来 3 秒内都攻击敌人 2 ,然后敌人 2 会被消灭,这段时间对 Bob 的总伤害是&nbsp;<code>2 + 2 + 2 = 6</code>&nbsp;点。</li>
<li>接下来 4 秒内都攻击敌人 3 ,然后敌人 3 会被消灭,这段时间对 Bob 的总伤害是&nbsp;<code>1 + 1 + 1 + 1 = 4</code>&nbsp;点。</li>
</ul>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>power = 8, damage = [40], health = [59]</span></p>
<p><span class="example-io"><b>输出:</b>320</span></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= power &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= n == damage.length == health.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= damage[i], health[i] &lt;= 10<sup>4</sup></code></li>
</ul>