leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2141.cpp (511B)


0 class Solution { 1 public: 2 long long maxRunTime(int n, const vector<int> &batteries) { 3 long long low = 1, high = reduce(batteries.begin(), batteries.end(), 0LL) / n; 4 while (low < high) { 5 long long mid = high - (high - low) / 2, sum = 0; 6 for (long long bat : batteries) 7 sum += min(bat, mid); 8 if (sum >= (long long)(n * mid)) 9 low = mid; 10 else 11 high = mid - 1; 12 } 13 return low; 14 } 15 };