TheRealSamuel/LeetCodeProblem
0572
1{2 "id": 2449,3 "name": "maximum_number_of_robots_within_budget",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/maximum-number-of-robots-within-budget/",6 "date": "1660953600000",7 "task_description": "You have `n` robots. You are given two **0-indexed** integer arrays, `chargeTimes` and `runningCosts`, both of length `n`. The `ith` robot costs `chargeTimes[i]` units to charge and costs `runningCosts[i]` units to run. You are also given an integer `budget`. The **total cost** of running `k` chosen robots is equal to `max(chargeTimes) + k * sum(runningCosts)`, where `max(chargeTimes)` is the largest charge cost among the `k` robots and `sum(runningCosts)` is the sum of running costs among the `k` 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` `1 <= n <= 5 * 104` `1 <= chargeTimes[i], runningCosts[i] <= 105` `1 <= budget <= 1015`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25",12 "output": "3 "13 },14 {15 "label": "Example 2",16 "input": "chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19",17 "output": "0 "18 }19 ],20 "private_test_cases": [21 {22 "input": [23 [24 60,25 57,26 78,27 28,28 25,29 31,30 65,31 53,32 67,33 1,34 46,35 99,36 58,37 3,38 93,39 8,40 21,41 23,42 58,43 2,44 21,45 96,46 37,47 74,48 100,49 6,50 61,51 86,52 19,53 41,54 71,55 37,56 59,57 51,58 52,59 96,60 65,61 60,62 92,63 64,64 79,65 49,66 19,67 77,68 30,69 40,70 22,71 68,72 100,73 7574 ],75 [76 64,77 76,78 57,79 23,80 11,81 47,82 81,83 12,84 98,85 39,86 58,87 87,88 61,89 46,90 84,91 87,92 31,93 19,94 77,95 85,96 74,97 59,98 68,99 93,100 69,101 44,102 88,103 33,104 64,105 11,106 3,107 30,108 75,109 78,110 1,111 38,112 38,113 43,114 45,115 91,116 49,117 98,118 24,119 93,120 26,121 12,122 54,123 40,124 78,125 50126 ],127 210870090785272128 ],129 "output": 50130 },131 {132 "input": [133 [134 55,135 91,136 84,137 85,138 85,139 68,140 46,141 32,142 55,143 3,144 64,145 50,146 80,147 75,148 66,149 81,150 29151 ],152 [153 69,154 82,155 4,156 13,157 97,158 97,159 50,160 44,161 20,162 93,163 65,164 50,165 9,166 67,167 100,168 95,169 31170 ],171 501158905863573172 ],173 "output": 17174 },175 {176 "input": [177 [178 68,179 14,180 1,181 56,182 93,183 41,184 32,185 30,186 24,187 22,188 67,189 70,190 76,191 74,192 43,193 55,194 36,195 78,196 33,197 53,198 50,199 87,200 91,201 40,202 37,203 94,204 92,205 75,206 4,207 90,208 61,209 22,210 96,211 42,212 58,213 63,214 68,215 96,216 6,217 21,218 28,219 71220 ],221 [222 85,223 28,224 34,225 85,226 10,227 20,228 100,229 80,230 89,231 82,232 65,233 3,234 39,235 13,236 44,237 90,238 64,239 10,240 96,241 73,242 88,243 60,244 70,245 72,246 46,247 86,248 11,249 63,250 64,251 44,252 83,253 25,254 92,255 83,256 12,257 36,258 33,259 8,260 18,261 84,262 54,263 74264 ],265 37288282987591266 ],267 "output": 42268 },269 {270 "input": [271 [272 12,273 89,274 12,275 9,276 36,277 92,278 93,279 88,280 30,281 98,282 6,283 3,284 52,285 30,286 50,287 41,288 12,289 6,290 41,291 51,292 79,293 56,294 27,295 97,296 99,297 54,298 6,299 55,300 42,301 50,302 74,303 51,304 27,305 85,306 97,307 68,308 71,309 10,310 46,311 72,312 62,313 99,314 30,315 6,316 21317 ],318 [319 27,320 39,321 69,322 1,323 9,324 79,325 28,326 16,327 15,328 24,329 82,330 46,331 29,332 47,333 71,334 95,335 45,336 48,337 92,338 64,339 10,340 47,341 46,342 3,343 27,344 94,345 51,346 84,347 70,348 99,349 67,350 88,351 70,352 11,353 54,354 61,355 98,356 54,357 23,358 41,359 17,360 64,361 13,362 5,363 68364 ],365 100631638339804366 ],367 "output": 45368 },369 {370 "input": [371 [372 92,373 34,374 85,375 61,376 54,377 41,378 27,379 35,380 49,381 86,382 61,383 36,384 4,385 79,386 65,387 40,388 46,389 60,390 19,391 18,392 71,393 72,394 8,395 9,396 56,397 65,398 96,399 64,400 52,401 12,402 3,403 9,404 44405 ],406 [407 99,408 78,409 48,410 30,411 37,412 70,413 70,414 86,415 56,416 46,417 62,418 90,419 85,420 93,421 87,422 75,423 63,424 14,425 78,426 28,427 31,428 35,429 82,430 82,431 29,432 35,433 72,434 58,435 52,436 21,437 47,438 72,439 47440 ],441 424239692664293442 ],443 "output": 33444 },445 {446 "input": [447 [448 95,449 66,450 39,451 93,452 90,453 98,454 47,455 94,456 62,457 30,458 19,459 49,460 55,461 98,462 87,463 64,464 63,465 60,466 31,467 28,468 64,469 77,470 79,471 91,472 29,473 61,474 70,475 71,476 11,477 35,478 64,479 87,480 46,481 28,482 17,483 44484 ],485 [486 74,487 2,488 58,489 52,490 21,491 72,492 43,493 37,494 9,495 1,496 88,497 38,498 97,499 38,500 61,501 38,502 61,503 22,504 75,505 21,506 31,507 58,508 58,509 87,510 16,511 1,512 16,513 56,514 11,515 60,516 2,517 91,518 9,519 37,520 68,521 10522 ],523 228180887669616524 ],525 "output": 36526 },527 {528 "input": [529 [530 23,531 73,532 21,533 71,534 55,535 59,536 9,537 78,538 50,539 58,540 30,541 10,542 75,543 65,544 82,545 24,546 23,547 43,548 58,549 100,550 65,551 86,552 10,553 86554 ],555 [556 81,557 63,558 54,559 22,560 22,561 1,562 32,563 26,564 73,565 59,566 21,567 57,568 6,569 52,570 25,571 75,572 38,573 37,574 8,575 98,576 39,577 52,578 50,579 33580 ],581 358813912220824582 ],583 "output": 24584 },585 {586 "input": [587 [588 91,589 87,590 87,591 63,592 19,593 91,594 74,595 91,596 62,597 96,598 85,599 86,600 12,601 2,602 16,603 65,604 84,605 92,606 5,607 88,608 32,609 28,610 61,611 3,612 8,613 95614 ],615 [616 67,617 78,618 78,619 74,620 9,621 48,622 94,623 76,624 98,625 14,626 17,627 50,628 39,629 72,630 98,631 84,632 67,633 42,634 8,635 1,636 25,637 89,638 46,639 45,640 63,641 36642 ],643 372085360977557644 ],645 "output": 26646 },647 {648 "input": [649 [650 21,651 73,652 14,653 68,654 100,655 83,656 91,657 81,658 72,659 24,660 61661 ],662 [663 65,664 98,665 78,666 84,667 2,668 64,669 88,670 18,671 30,672 88,673 57674 ],675 275993940081086676 ],677 "output": 11678 },679 {680 "input": [681 [682 55,683 9,684 13,685 100,686 30,687 6,688 42,689 83,690 66,691 18,692 40,693 24,694 99,695 46,696 26,697 74,698 89,699 58,700 14,701 90,702 27,703 76,704 50,705 31,706 96,707 62,708 20709 ],710 [711 70,712 7,713 59,714 97,715 77,716 57,717 25,718 3,719 84,720 24,721 47,722 1,723 33,724 81,725 74,726 53,727 46,728 41,729 7,730 72,731 8,732 59,733 17,734 3,735 63,736 80,737 87738 ],739 89438979818988740 ],741 "output": 27742 }743 ],744 "haskell_template": "maximumRobots :: [Int] -> [Int] -> Int -> Int\nmaximumRobots chargeTimes runningCosts budget ",745 "ocaml_template": "let maximumRobots (chargeTimes: int list) (runningCosts: int list) (budget: int) : int = ",746 "scala_template": "def maximumRobots(chargeTimes: List[Int],runningCosts: List[Int],budget: Int): Int = { \n \n}",747 "java_template": "public static int maximumRobots(List<Integer> chargeTimes, List<Integer> runningCosts, int budget) {\n\n}",748 "python_template": "class Solution(object):\n def maximumRobots(self, chargeTimes, runningCosts, budget):\n \"\"\"\n :type chargeTimes: List[int]\n :type runningCosts: List[int]\n :type budget: int\n :rtype: int\n \"\"\"\n "749}