use std::io::{BufReader, Write}; macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let mut s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } /// https://maguro.dev/debug-macro/ #[allow(unused_macros)] macro_rules! debug { ($($a:expr),* $(,)*) => { #[cfg(debug_assertions)] eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*); #[cfg(debug_assertions)] std::io::stderr().flush().unwrap(); }; } #[allow(dead_code)] fn concat_newline(chg: &mut String, additional: &str){ chg.push_str(additional); chg.push_str("\n"); } #[allow(dead_code)] fn concat_whitespace(chg: &mut String, additional: &str){ chg.push_str(additional); chg.push_str(" "); } fn main(){ println!("{}", solve()); } fn solve()->String{ let mut ans= String::new(); input!{ n: usize, w: usize, p: [(usize, u64); n], } // maxを更新できる価値を与える let mut from: Vec = Vec::new(); let mut to: Vec = Vec::new(); from.resize(w+1,0); to.resize(w+1, 0); for i in 0..n { let (weight, value) = p[i]; for j in 0..=w { if j > 0 { to[j] = to[j-1].max(from[j]); } if j >= weight { to[j] = std::cmp::max(to[j], from[j-weight] + value); } } std::mem::swap(&mut from, &mut to); } let dp = from; for x in 1..=w { concat_newline(&mut ans, (dp[w] - dp[w-x] + 1).to_string().as_str()); } return ans; }