use std::collections::HashSet; use std::io; fn main() { let mut input_line = String::new(); io::stdin().read_line(&mut input_line).unwrap(); let mut iter = input_line.trim().split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let m: usize = iter.next().unwrap().parse().unwrap(); let k: usize = iter.next().unwrap().parse().unwrap(); let mut input_line = String::new(); io::stdin().read_line(&mut input_line).unwrap(); let a: Vec = input_line .trim() .split_whitespace() .map(|x| x.parse().unwrap()) .collect();use std::io; fn main() { let mut input = String::new(); io::stdin().read_line(&mut input).expect("Failed to read line"); let mut iter = input.trim().split_whitespace(); let n: usize = iter.next().unwrap().parse().expect("Failed to parse N"); let m: i32 = iter.next().unwrap().parse().expect("Failed to parse M"); let k: usize = iter.next().unwrap().parse().expect("Failed to parse K"); input.clear(); io::stdin().read_line(&mut input).expect("Failed to read line"); let a: Vec = input .trim() .split_whitespace() .map(|x| x.parse().expect("Failed to parse element of A")) .collect(); let mut s = vec![false; m as usize + 1]; s[0] = true; for _ in 0..k { let mut ns = vec![false; m as usize + 1]; ns[0] = true; for i in 0..s.len() { if s[i] { for &ai in &a { let idx = i as i32 + ai; if idx <= m { ns[idx as usize] = true; } } } } s = ns; } let result = s.iter().rposition(|&x| x).unwrap_or(0); println!("{}", result); } let mut s: HashSet = HashSet::new(); s.insert(0); for _ in 0..k { let mut ns: HashSet = HashSet::new(); ns.insert(0); for &si in &s { for &ai in &a { if si + ai <= m { ns.insert(si + ai); } } } s = ns; } if let Some(&max_val) = s.iter().max() { println!("{}", max_val); } }