Skip to content
Discussion options

You must be logged in to vote

We can use binary search to find the maximum time T such that all n computers can run simultaneously for T minutes. For a given T, we check if the sum of min(batteries[i], T) over all batteries is at least n × T. This condition is necessary and sufficient because each battery can contribute at most T minutes to the total runtime (or its full capacity if less than T), and we can schedule the batteries arbitrarily.

We set the lower bound low = 0 and the upper bound high = ⌊sum(batteries)⌋. Then we perform binary search to find the maximum T that satisfies the condition.

Approach:

  • Binary Search on Answer: Since we want the maximum run time, we can perform binary search over possible run tim…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Dec 1, 2025
Maintainer Author

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Dec 1, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 1, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants