Skip to main content

2141. Maximum Running Time of N Computers

link

class Solution:
def maxRunTime(self, n: int, batteries: List[int]) -> int:

l, r = 0, sum(batteries) // n

# greedy
def check(x):
return sum(min(x, b) for b in batteries) >= n * x # required capacity

while l < r:
mid = r - (r - l)//2
if check(mid):
l = mid
else:
r = mid-1
return r