// ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next(&mut self) -> T { self.it.next().unwrap().parse::().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec { self.it.next().unwrap().chars().collect() } pub fn next_vec(&mut self, len: usize) -> Vec { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter) { let t: u32 = sc.next(); for _ in 0..t { let n: usize = sc.next(); let w: usize = sc.next(); let a: Vec = sc.next_vec(n); let ans = solve(w, a); writeln!(out, "{}", ans).ok(); } } fn solve(w: usize, cost: Vec) -> u64 { let mut f = vec![1, 2]; f.resize(cost.len(), 0); for i in 2..f.len() { f[i] = f[i - 1] + f[i - 2]; } let mut dp = vec![(0, 0)]; for (i, cost) in cost.iter().enumerate().rev() { for j in (0..dp.len()).rev() { let (a, b) = dp[j]; if a + *cost <= w { dp.push((a + *cost, b + f[i])); } } dp.sort_by_key(|p| (p.0, !p.1)); dp.dedup_by(|a, b| a.1 <= b.1); let rem = f[..i].iter().sum::(); let last = *dp.last().unwrap(); dp.retain(|p| p.1 + rem >= last.1); } dp.last().unwrap().1 }