use std::io::stdin; trait OrdTools: Ord + Clone + Sized { fn chmin(&mut self, x: Self) { *self = std::cmp::min(self.clone(), x); } fn chmax(&mut self, x: Self) { *self = std::cmp::max(self.clone(), x); } } impl OrdTools for T {} fn main() { let (n, l) = { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); let s = s.trim_end().to_owned(); let mut s = s.split_whitespace(); let n: usize = s.next().unwrap().parse().unwrap(); let l: usize = s.next().unwrap().parse().unwrap(); assert!(s.next().is_none()); (n, l) }; let a = { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); let s = s.trim_end().to_owned(); let mut s = s.split_whitespace(); let mut a = vec![0; n]; a.iter_mut() .for_each(|x| *x = s.next().unwrap().parse().unwrap()); assert!(s.next().is_none()); a }; let mut ans = vec![std::i32::MIN; n]; let mut dp = vec![vec![vec![std::i32::MIN; n]; n]; l + 1]; (0..n).for_each(|j| dp[l][j][j] = l as i32 * a[j]); for i in (0..=l).rev() { if i + 3 <= l { let prv = dp[i + 2].clone(); for j in 0..n { for k in 0..n { dp[i][j][k].chmax(prv[j][k]); } } } for j in 0..n { let crr = dp[i][j].clone(); let mut update = |ni: usize, nj: usize, nk: usize, k| { dp[ni][nj][nk].chmax(crr[k] + ni as i32 * a[nj]); }; for k in (0..=j).filter(|&k| crr[k] != std::i32::MIN) { let d = j - k; if d + 1 <= i && 0 < k { update(i - d - 1, k - 1, j, k); } if 0 < i && j < n - 1 { update(i - 1, j + 1, k, k); } } for k in (j..n).filter(|&k| crr[k] != std::i32::MIN) { let d = k - j; if 0 < i && 0 < j { update(i - 1, j - 1, k, k); } if d + 1 <= i && k < n - 1 { update(i - d - 1, k + 1, j, k); } } if j + i < n { (j + 1..n).for_each(|k| ans[j + i].chmax(crr[k])); } if i <= j { (0..=j - i).for_each(|k| ans[j - i].chmax(crr[k])); } } } ans.iter().for_each(|x| println!("{}", x)); }