use std::collections::BTreeMap; fn main() { let (n, k, x, y) = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); ( iter.next().unwrap().parse::().unwrap(), iter.next().unwrap().parse::().unwrap(), iter.next().unwrap().parse::().unwrap(), iter.next().unwrap().parse::().unwrap(), ) }; let a: Vec = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.split_whitespace().map(|x| x.parse().unwrap()).collect() }; let mut map: BTreeMap = BTreeMap::new(); for x in a { let count = map.entry((x + k - 2) / k).or_insert(0); *count += 1; } let mut ans: u64 = 0; let mut sum: u64 = n; let mut healed: u64 = 0; let heal_more: u64 = y / x; for (heal, count) in map { if sum <= heal_more { ans += x * sum * (heal - healed); } else { ans += y * (heal - healed); } sum -= count; healed = heal; } println!("{}", ans); }