mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
problem(rs): add “2141. Maximum Running Time of N Computers”
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
c2480838e5
commit
8275274674
1 changed files with 18 additions and 0 deletions
18
problems/rs/maximum-running-time-of-n-computers.rs
Normal file
18
problems/rs/maximum-running-time-of-n-computers.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
impl Solution {
|
||||
pub fn max_run_time(n: i32, mut batteries: Vec<i32>) -> i64 {
|
||||
batteries.sort();
|
||||
|
||||
let mut total = batteries.iter().map(|x| *x as u64).sum::<u64>();
|
||||
let mut k: u64 = 0;
|
||||
|
||||
while *batteries.last().unwrap() as u64 > total / (n as u64 - k) {
|
||||
total -= *batteries.last().unwrap() as u64;
|
||||
batteries.pop();
|
||||
|
||||
k += 1;
|
||||
}
|
||||
|
||||
(total / (n as u64 - k)) as i64
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue