classSolution: defmaxRunTime(self, n, batteries): left = 0 right = sum(batteries) // n max_time = 0 while left <= right: mid = (left + right) // 2 total = 0 for cap in batteries: total += min(cap, mid) if total >= mid * n: max_time = mid left = mid + 1 else: right = mid - 1 return max_time