Class Solution
java.lang.Object
g2301_2400.s2398_maximum_number_of_robots_within_budget.Solution
2398 - Maximum Number of Robots Within Budget.<p>Hard</p>
<p>You have <code>n</code> robots. You are given two <strong>0-indexed</strong> integer arrays, <code>chargeTimes</code> and <code>runningCosts</code>, both of length <code>n</code>. The <code>i<sup>th</sup></code> robot costs <code>chargeTimes[i]</code> units to charge and costs <code>runningCosts[i]</code> units to run. You are also given an integer <code>budget</code>.</p>
<p>The <strong>total cost</strong> of running <code>k</code> chosen robots is equal to <code>max(chargeTimes) + k * sum(runningCosts)</code>, where <code>max(chargeTimes)</code> is the largest charge cost among the <code>k</code> robots and <code>sum(runningCosts)</code> is the sum of running costs among the <code>k</code> robots.</p>
<p>Return <em>the <strong>maximum</strong> number of <strong>consecutive</strong> robots you can run such that the total cost <strong>does not</strong> exceed</em> <code>budget</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>It is possible to run all individual and consecutive pairs of robots within budget.</p>
<p>To obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 which is less than 25.</p>
<p>It can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> No robot can be run that does not exceed the budget, so we return 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>chargeTimes.length == runningCosts.length == n</code></li>
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
<li><code>1 <= chargeTimes[i], runningCosts[i] <= 10<sup>5</sup></code></li>
<li><code>1 <= budget <= 10<sup>15</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
maximumRobots
(int[] chargeTimes, int[] runningCosts, long budget)
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumRobots
public int maximumRobots(int[] chargeTimes, int[] runningCosts, long budget)
-