1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-12 19:01:47 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/从数量最多的堆取走礼物 [take-gifts-from-the-richest-pile].html
2025-01-09 20:29:41 +08:00

47 lines
1.5 KiB
HTML
Raw Permalink 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>给你一个整数数组 <code>gifts</code> ,表示各堆礼物的数量。每一秒,你需要执行以下操作:</p>
<ul>
<li>选择礼物数量最多的那一堆。</li>
<li>如果不止一堆都符合礼物数量最多,从中选择任一堆即可。</li>
<li>将堆中的礼物数量减少到堆中原来礼物数量的平方根,向下取整。</li>
</ul>
<p>返回在 <code>k</code> 秒后剩下的礼物数量<em></em></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>gifts = [25,64,9,4,100], k = 4
<strong>输出:</strong>29
<strong>解释:</strong>
按下述方式取走礼物:
- 在第一秒,选中最后一堆,剩下 10 个礼物。
- 接着第二秒选中第二堆礼物,剩下 8 个礼物。
- 然后选中第一堆礼物,剩下 5 个礼物。
- 最后,再次选中最后一堆礼物,剩下 3 个礼物。
最后剩下的礼物数量分别是 [5,8,9,4,3] ,所以,剩下礼物的总数量是 29 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>gifts = [1,1,1,1], k = 4
<strong>输出:</strong>4
<strong>解释:</strong>
在本例中,不管选中哪一堆礼物,都必须剩下 1 个礼物。
也就是说,你无法获取任一堆中的礼物。
所以,剩下礼物的总数量是 4 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= gifts.length &lt;= 10<sup>3</sup></code></li>
<li><code>1 &lt;= gifts[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>3</sup></code></li>
</ul>