Skip to content

Commit 47b25fc

Browse files
authored
Create 2141. Maximum Running Time of N Computers 1 (#946)
2 parents a5bfa70 + bb7b8b4 commit 47b25fc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
long long maxRunTime(int n, vector<int>& batteries) {
4+
long long sum = 0;
5+
for (long long b : batteries) sum += b;
6+
7+
long long l = 0, r = sum / n;
8+
9+
while (l < r) {
10+
long long m = (l + r + 1) >> 1;
11+
long long need = n * m, have = 0;
12+
13+
for (long long b : batteries)
14+
have += min(b, m);
15+
16+
if (have >= need) l = m;
17+
else r = m - 1;
18+
}
19+
return l;
20+
}
21+
};

0 commit comments

Comments
 (0)