Class Solution
java.lang.Object
g1701_1800.s1705_maximum_number_of_eaten_apples.Solution
1705 - Maximum Number of Eaten Apples.<p>Medium</p>
<p>There is a special kind of apple tree that grows apples every day for <code>n</code> days. On the <code>i<sup>th</sup></code> day, the tree grows <code>apples[i]</code> apples that will rot after <code>days[i]</code> days, that is on day <code>i + days[i]</code> the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by <code>apples[i] == 0</code> and <code>days[i] == 0</code>.</p>
<p>You decided to eat <strong>at most</strong> one apple a day (to keep the doctors away). Note that you can keep eating after the first <code>n</code> days.</p>
<p>Given two integer arrays <code>days</code> and <code>apples</code> of length <code>n</code>, return <em>the maximum number of apples you can eat.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> apples = [1,2,3,5,2], days = [3,2,1,4,2]</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong> You can eat 7 apples:</p>
<ul>
<li>
<p>On the first day, you eat an apple that grew on the first day.</p>
</li>
<li>
<p>On the second day, you eat an apple that grew on the second day.</p>
</li>
<li>
<p>On the third day, you eat an apple that grew on the second day. After this day, the apples that grew on the third day rot.</p>
</li>
<li>
<p>On the fourth to the seventh days, you eat apples that grew on the fourth day.</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> You can eat 5 apples:</p>
<ul>
<li>
<p>On the first to the third day you eat apples that grew on the first day.</p>
</li>
<li>
<p>Do nothing on the fouth and fifth days.</p>
</li>
<li>
<p>On the sixth and seventh days you eat apples that grew on the sixth day.</p>
</li>
</ul>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == apples.length == days.length</code></li>
<li><code>1 <= n <= 2 * 10<sup>4</sup></code></li>
<li><code>0 <= apples[i], days[i] <= 2 * 10<sup>4</sup></code></li>
<li><code>days[i] = 0</code> if and only if <code>apples[i] = 0</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
eatenApples
public int eatenApples(int[] apples, int[] days)
-