2021-07-14 12:25
中山大学 深度学习 SunburstRun:use std::io::{BufRead, Write};
use std::str::FromStr;
fn solve(mut input: impl BufRead, mut output: impl Write) {
let mut buf = String::new();
input.read_line(&mut buf);
let n: usize = buf.trim_end().parse().unwrap();
buf.clear();
input.read_line(&mut buf);
let mut nums: Vec<usize> = buf
.trim_end()
.split(' ')
.map(usize::from_str)
.flatten()
.collect();
let mut sum = vec![nums[0]];
for i in 1..n {
sum.push(sum[i - 1] + nums[i]);
}
let mut st = vec![0];
let mut ans = 0;
for i in 1..n {
while let Some(top) = st.pop() {
if nums[top] < nums[i] {
st.push(top);
break;
}
ans =
ans.max((sum[i - 1] - st.last().copied().map(|c| sum[c]).unwrap_or(0)) * nums[top]);
}
st.push(i);
}
writeln!(output, "{}", ans);
}
fn main() {
solve(std::io::stdin().lock(), std::io::stdout());
}
0 点赞 评论 收藏
分享
关注他的用户也关注了: