20241101 finished.
This commit is contained in:
parent
22e2fbeec7
commit
f1aaf32db6
|
@ -288,3 +288,5 @@ mod p3211_generate_binary_strings_without_adjacent_zeros;
|
|||
mod p3216_lexicographically_smallest_string_after_a_swap;
|
||||
|
||||
mod p3165_maximum_sum_of_subsequence_with_non_adjacent_elements;
|
||||
|
||||
mod p3259_maximum_energy_boost_from_two_drinks;
|
||||
|
|
42
src/problem/p3259_maximum_energy_boost_from_two_drinks.rs
Normal file
42
src/problem/p3259_maximum_energy_boost_from_two_drinks.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* [3259] Maximum Energy Boost From Two Drinks
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn max_energy_boost(energy_drink_a: Vec<i32>, energy_drink_b: Vec<i32>) -> i64 {
|
||||
let n = energy_drink_a.len();
|
||||
let mut dp_drink_a = vec![0; n];
|
||||
let mut dp_drink_b = vec![0; n];
|
||||
|
||||
for i in 0..n {
|
||||
if i >= 2 {
|
||||
dp_drink_a[i] = dp_drink_a[i - 1].max(dp_drink_b[i - 2]) + energy_drink_a[i] as i64;
|
||||
dp_drink_b[i] = dp_drink_b[i - 1].max(dp_drink_a[i - 2]) + energy_drink_b[i] as i64;
|
||||
} else if i >= 1 {
|
||||
dp_drink_a[i] = dp_drink_a[i - 1] + energy_drink_a[i] as i64;
|
||||
dp_drink_b[i] = dp_drink_b[i - 1] + energy_drink_b[i] as i64;
|
||||
} else {
|
||||
dp_drink_a[i] = energy_drink_a[i] as i64;
|
||||
dp_drink_b[i] = energy_drink_b[i] as i64;
|
||||
}
|
||||
}
|
||||
|
||||
dp_drink_a[n - 1].max(dp_drink_b[n - 1])
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_3259() {
|
||||
assert_eq!(5, Solution::max_energy_boost(vec![1, 3, 1], vec![3, 1, 1]));
|
||||
assert_eq!(7, Solution::max_energy_boost(vec![4, 1, 1], vec![1, 1, 3]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user