Skip to content

Commit

Permalink
past16-open h
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 4, 2024
1 parent 24aa4f9 commit 1f33de7
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions cargo-atcoder-1.70.0/contests/past16-open/src/bin/h.rs
@@ -1,10 +1,32 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
m: usize,
a: [usize; n],
}
let mut dp = vec![vec![None; 2]; n + 1];
dp[0][0] = Some(0_usize);
for a_i in a.iter().copied() {
let mut next = vec![vec![None; 2]; n + 1];
for j in 0..=n {
if let Some(v) = dp[j][0] {
next[j][0] = next[j][0].max(Some(v + a_i));
if j + 1 <= n {
next[j + 1][1] = next[j + 1][1].max(Some(v));
}
}
if let Some(v) = dp[j][1] {
next[j][0] = next[j][0].max(Some(v + a_i));
}
}
dp = next;
}

let mut ans = 0_usize;
for i in m..=n {
ans = ans.max(dp[i][0].max(dp[i][1]).unwrap_or(0));
}
println!("{}", ans);
}

0 comments on commit 1f33de7

Please sign in to comment.