diff --git a/storage/zeta/rs/completed/15407.rs b/storage/zeta/rs/completed/15407.rs new file mode 100644 index 0000000..73d5df7 --- /dev/null +++ b/storage/zeta/rs/completed/15407.rs @@ -0,0 +1,30 @@ +use std::io::{read_to_string, stdin}; + +fn main() { + let temp = read_to_string(stdin()).unwrap(); + let mut iter = temp + .split_ascii_whitespace() + .map(|x| x.parse::().unwrap()); + + let n = iter.next().unwrap(); + let mut ta = iter.next().unwrap(); + let mut tv = 0; + let mut items = (0..n) + .map(|_| (iter.next().unwrap(), iter.next().unwrap())) + .collect::>(); + + items.sort(); + + while ta > 0 && items.len() > 0 { + let (v, a) = items.pop().unwrap(); + if a >= ta { + tv += v * ta; + ta = 0; + } else { + tv += v * a; + ta -= a; + } + } + + println!("{}", tv); +} diff --git a/storage/zeta/rs/completed/24305.rs b/storage/zeta/rs/completed/24305.rs new file mode 100644 index 0000000..8c85287 --- /dev/null +++ b/storage/zeta/rs/completed/24305.rs @@ -0,0 +1,36 @@ +use std::io::{read_to_string, stdin}; + +fn main() { + let temp = read_to_string(stdin()).unwrap(); + let mut iter = temp + .split_ascii_whitespace() + .map(|x| x.parse::().unwrap()); + let n = iter.next().unwrap(); + let arr = (0..n).map(|i| (i + 1, iter.next().unwrap())); + + let mut stack = vec![]; + + for e in arr { + if stack.is_empty() { + stack.push(e); + print!("{} ", 0); + } else { + while let Some(top) = stack.last() { + if top.1 >= e.1 { + stack.pop(); + } else { + break; + } + } + + if stack.is_empty() { + stack.push(e); + print!("{} ", 0); + } else { + print!("{} ", stack.last().unwrap().0); + stack.push(e); + } + + } + } +}