Class Solution
-
- All Implemented Interfaces:
public final class Solution
2398 - Maximum Number of Robots Within Budget.
Hard
You have
n
robots. You are given two 0-indexed integer arrays,chargeTimes
andrunningCosts
, both of lengthn
. The <code>i<sup>th</sup></code> robot costschargeTimes[i]
units to charge and costsrunningCosts[i]
units to run. You are also given an integerbudget
.The total cost of running
k
chosen robots is equal tomax(chargeTimes) + k * sum(runningCosts)
, wheremax(chargeTimes)
is the largest charge cost among thek
robots andsum(runningCosts)
is the sum of running costs among thek
robots.Return the maximum number of consecutive robots you can run such that the total cost does not exceed
budget
.Example 1:
Input: chargeTimes = 3,6,1,3,4, runningCosts = 2,1,3,4,5, budget = 25
Output: 3
Explanation:
It is possible to run all individual and consecutive pairs of robots within budget.
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.
It can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.
Example 2:
Input: chargeTimes = 11,12,19, runningCosts = 10,8,7, budget = 19
Output: 0
Explanation: No robot can be run that does not exceed the budget, so we return 0.
Constraints:
chargeTimes.length == runningCosts.length == n
<code>1 <= n <= 5 * 10<sup>4</sup></code>
<code>1 <= chargeTimesi, runningCostsi<= 10<sup>5</sup></code>
<code>1 <= budget <= 10<sup>15</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Integer
maximumRobots(IntArray chargeTimes, IntArray runningCosts, Long budget)
-
-
Method Detail
-
maximumRobots
final Integer maximumRobots(IntArray chargeTimes, IntArray runningCosts, Long budget)
-
-
-
-