You are the manager of a robotic manufacturing plant and need to optimize the operation of your robots within a limited budget. You have n robots available, each with different charging and operational costs.
Given two arrays:
chargeTimes[i]- the cost to charge the i-th robotrunningCosts[i]- the ongoing operational cost per unit time for the i-th robot
The total cost of running k consecutive robots is calculated as:
Total Cost = max(chargeTimes) + k ร sum(runningCosts)
Where max(chargeTimes) is the highest charging cost among the selected robots, and sum(runningCosts) is the sum of all operational costs.
Goal: Find the maximum number of consecutive robots you can operate without exceeding your budget.
Input & Output
Visualization
Time & Space Complexity
O(log n) binary search iterations, each taking O(n) time for sliding window check
Space for deque in sliding window validation
Constraints
- 1 โค chargeTimes.length == runningCosts.length โค 5 ร 104
- 1 โค chargeTimes[i], runningCosts[i] โค 105
- 1 โค budget โค 1015
- All robots must be consecutive in the array