|
| 1 | +--- |
| 2 | +comments: true |
| 3 | +difficulty: 困难 |
| 4 | +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README.md |
| 5 | +--- |
| 6 | + |
| 7 | +<!-- problem:start --> |
| 8 | + |
| 9 | +# [3506. Find Time Required to Eliminate Bacterial Strains II 🔒](https://leetcode.cn/problems/find-time-required-to-eliminate-bacterial-strains-ii) |
| 10 | + |
| 11 | +[English Version](/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README_EN.md) |
| 12 | + |
| 13 | +## 题目描述 |
| 14 | + |
| 15 | +<!-- description:start --> |
| 16 | + |
| 17 | +<p>You are given an integer array <code>timeReq</code> and an integer <code>splitTime</code>.</p> |
| 18 | + |
| 19 | +<p>In the microscopic world of the human body, the immune system faces an extraordinary challenge: combatting a rapidly multiplying bacterial colony that threatens the body's survival.</p> |
| 20 | + |
| 21 | +<p>Initially, only one <strong>white blood cell</strong> (<strong>WBC</strong>) is deployed to eliminate the bacteria. However, the lone WBC quickly realizes it cannot keep up with the bacterial growth rate.</p> |
| 22 | + |
| 23 | +<p>The WBC devises a clever strategy to fight the bacteria:</p> |
| 24 | + |
| 25 | +<ul> |
| 26 | + <li>The <code>i<sup>th</sup></code> bacterial strain takes <code>timeReq[i]</code> units of time to be eliminated.</li> |
| 27 | + <li>A single WBC can eliminate <strong>only one</strong> bacterial strain. Afterwards, the WBC is exhausted and cannot perform any other tasks.</li> |
| 28 | + <li>A WBC can split itself into two WBCs, but this requires <code>splitTime</code> units of time. Once split, the two WBCs can work in <strong>parallel</strong> on eliminating the bacteria.</li> |
| 29 | + <li><em>Only one</em> WBC can work on a single bacterial strain. Multiple WBCs <strong>cannot</strong> attack one strain in parallel.</li> |
| 30 | +</ul> |
| 31 | + |
| 32 | +<p>You must determine the <strong>minimum</strong> time required to eliminate all the bacterial strains.</p> |
| 33 | + |
| 34 | +<p><strong>Note</strong> that the bacterial strains can be eliminated in any order.</p> |
| 35 | + |
| 36 | +<p> </p> |
| 37 | +<p><strong class="example">Example 1:</strong></p> |
| 38 | + |
| 39 | +<div class="example-block"> |
| 40 | +<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4,5], splitTime = 2</span></p> |
| 41 | + |
| 42 | +<p><strong>Output:</strong> <span class="example-io">12</span></p> |
| 43 | + |
| 44 | +<p><strong>Explanation:</strong></p> |
| 45 | + |
| 46 | +<p>The elimination process goes as follows:</p> |
| 47 | + |
| 48 | +<ul> |
| 49 | + <li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 2 units of time.</li> |
| 50 | + <li>One of the WBCs eliminates strain 0 at a time <code>t = 2 + 10 = 12.</code> The other WBC splits again, using 2 units of time.</li> |
| 51 | + <li>The 2 new WBCs eliminate the bacteria at times <code>t = 2 + 2 + 4</code> and <code>t = 2 + 2 + 5</code>.</li> |
| 52 | +</ul> |
| 53 | +</div> |
| 54 | + |
| 55 | +<p><strong class="example">Example 2:</strong></p> |
| 56 | + |
| 57 | +<div class="example-block"> |
| 58 | +<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4], splitTime = 5</span></p> |
| 59 | + |
| 60 | +<p><strong>Output:</strong>15</p> |
| 61 | + |
| 62 | +<p><strong>Explanation:</strong></p> |
| 63 | + |
| 64 | +<p>The elimination process goes as follows:</p> |
| 65 | + |
| 66 | +<ul> |
| 67 | + <li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 5 units of time.</li> |
| 68 | + <li>The 2 new WBCs eliminate the bacteria at times <code>t = 5 + 10</code> and <code>t = 5 + 4</code>.</li> |
| 69 | +</ul> |
| 70 | +</div> |
| 71 | + |
| 72 | +<p> </p> |
| 73 | +<p><strong>Constraints:</strong></p> |
| 74 | + |
| 75 | +<ul> |
| 76 | + <li><code>2 <= timeReq.length <= 10<sup>5</sup></code></li> |
| 77 | + <li><code>1 <= timeReq[i] <= 10<sup>9</sup></code></li> |
| 78 | + <li><code>1 <= splitTime <= 10<sup>9</sup></code></li> |
| 79 | +</ul> |
| 80 | + |
| 81 | +<!-- description:end --> |
| 82 | + |
| 83 | +## 解法 |
| 84 | + |
| 85 | +<!-- solution:start --> |
| 86 | + |
| 87 | +### 方法一 |
| 88 | + |
| 89 | +<!-- tabs:start --> |
| 90 | + |
| 91 | +#### Python3 |
| 92 | + |
| 93 | +```python |
| 94 | + |
| 95 | +``` |
| 96 | + |
| 97 | +#### Java |
| 98 | + |
| 99 | +```java |
| 100 | + |
| 101 | +``` |
| 102 | + |
| 103 | +#### C++ |
| 104 | + |
| 105 | +```cpp |
| 106 | + |
| 107 | +``` |
| 108 | + |
| 109 | +#### Go |
| 110 | + |
| 111 | +```go |
| 112 | + |
| 113 | +``` |
| 114 | + |
| 115 | +<!-- tabs:end --> |
| 116 | + |
| 117 | +<!-- solution:end --> |
| 118 | + |
| 119 | +<!-- problem:end --> |
0 commit comments