use proconio::input; fn main() { input! { n:usize, y:[usize;n], } let y_max = *y.iter().max().unwrap(); let mut dp = vec![vec![0; y_max + 1]; n]; let mut min_cum = vec![0; y_max + 1]; for i in 0..n { for j in 0..=y_max { dp[i][j] = j.abs_diff(y[i]) + min_cum[j]; if j != 0 { min_cum[j] = min_cum[j - 1].min(dp[i][j]); } else { min_cum[j] = dp[i][j]; } } } let ans = *dp[n - 1].iter().min().unwrap(); println!("{}", ans); }