|
| 1 | +<h2><a href="https://leetcode.com/problems/take-gifts-from-the-richest-pile/">2558. Take Gifts From the Richest Pile</a></h2><h3>Easy</h3><hr><div><p>You are given an integer array <code>gifts</code> denoting the number of gifts in various piles. Every second, you do the following:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>Choose the pile with the maximum number of gifts.</li> |
| 5 | + <li>If there is more than one pile with the maximum number of gifts, choose any.</li> |
| 6 | + <li>Leave behind the floor of the square root of the number of gifts in the pile. Take the rest of the gifts.</li> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p>Return <em>the number of gifts remaining after </em><code>k</code><em> seconds.</em></p> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<pre><strong>Input:</strong> gifts = [25,64,9,4,100], k = 4 |
| 15 | +<strong>Output:</strong> 29 |
| 16 | +<strong>Explanation:</strong> |
| 17 | +The gifts are taken in the following way: |
| 18 | +- In the first second, the last pile is chosen and 10 gifts are left behind. |
| 19 | +- Then the second pile is chosen and 8 gifts are left behind. |
| 20 | +- After that the first pile is chosen and 5 gifts are left behind. |
| 21 | +- Finally, the last pile is chosen again and 3 gifts are left behind. |
| 22 | +The final remaining gifts are [5,8,9,4,3], so the total number of gifts remaining is 29. |
| 23 | +</pre> |
| 24 | + |
| 25 | +<p><strong class="example">Example 2:</strong></p> |
| 26 | + |
| 27 | +<pre><strong>Input:</strong> gifts = [1,1,1,1], k = 4 |
| 28 | +<strong>Output:</strong> 4 |
| 29 | +<strong>Explanation:</strong> |
| 30 | +In this case, regardless which pile you choose, you have to leave behind 1 gift in each pile. |
| 31 | +That is, you can't take any pile with you. |
| 32 | +So, the total gifts remaining are 4. |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>1 <= gifts.length <= 10<sup>3</sup></code></li> |
| 40 | + <li><code>1 <= gifts[i] <= 10<sup>9</sup></code></li> |
| 41 | + <li><code>1 <= k <= 10<sup>3</sup></code></li> |
| 42 | +</ul> |
| 43 | +</div> |
0 commit comments