From 3fb395edac6abfc974d8ed90068f3d70e9f82452 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 30 Mar 2026 15:57:27 +0900 Subject: [PATCH] complete 1725.rs --- storage/zeta/rs/completed/1725.rs | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 storage/zeta/rs/completed/1725.rs diff --git a/storage/zeta/rs/completed/1725.rs b/storage/zeta/rs/completed/1725.rs new file mode 100644 index 0000000..d71610d --- /dev/null +++ b/storage/zeta/rs/completed/1725.rs @@ -0,0 +1,42 @@ +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 arr = (0..n).map(|_| iter.next().unwrap()).collect::>(); + + let mut stack = vec![(0, 0)]; + let mut res = 0; + for i in 1..=n { + let e = arr[i - 1]; + let (mut top_i, mut top_e) = *stack.last().unwrap(); + + while top_e >= e { + let (p_i, p_e) = stack.pop().unwrap(); + if stack.is_empty() { + break; + } + (top_i, top_e) = *stack.last().unwrap(); + res = res.max((i - top_i - 1) * p_e); + + } + if stack.is_empty() { + stack.push((i, e)); + continue; + } + stack.push((i, e)); + res = res.max((i - top_i) * e); + } + while stack.len() > 1 { + let (ti, te) = stack.pop().unwrap(); + let (top_i, top_e) = stack.last().unwrap(); + res = res.max((n - top_i) * te); + + } + + println!("{}", res); +}