use std::cmp::*; use std::io::*; fn check(v: u128, a: &Vec, x: u128, y: u128, k: u128) -> u128 { let mut res = v * y; for i in 0..a.len() { let d = a[i].saturating_sub(v * k); if d > 1 { res += (d - 1 + k - 1) / k * x; } } res } fn main() { let mut s: String = String::new(); stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let k: u128 = itr.next().unwrap().parse().unwrap(); let x: u128 = itr.next().unwrap().parse().unwrap(); let y: u128 = itr.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut r = 1u128 << 60; let mut l = 0; while r - l > 10 { let llr = (l + l + r) / 3; let lrr = (l + r + r) / 3; let vl = check(llr, &a, x, y, k); let vr = check(lrr, &a, x, y, k); if vl > vr { l = llr; } else { r = lrr; } } let mut ans = 1u128 << 60; for i in l..l + 10 { ans = min(ans, check(i, &a, x, y, k)); } println!("{}", ans); }