class Scanner { private var stack = [String]() private var index = 0 func peek() -> String { if stack.count == index { stack += readLine()!.split(separator: " ").map{ String($0) } } return stack[index] } func next() -> String { let value = peek() index += 1 return value } func nextInt() -> Int { return Int(next())! } func nextDouble() -> Double { return Double(next())! } } extension String { var characters: [Character] { self.map{ $0 } } } var scanner = Scanner() let N = scanner.nextInt() let K = scanner.nextInt() let X = scanner.nextInt() let Y = scanner.nextInt() var A = [Int]() for _ in 0 ..< N { A.append(scanner.nextInt() - 1) } A.sort() func howmany(_ a: Int, _ b: Int) -> Int { if a < 0 { return 0 } return a / b + (a % b != 0 ? 1 : 0) } var all = 0 var answer = 0 for i in 0 ..< N { let k = howmany(A[i] - K * all, K) if Y < (N - i) * X { all += k answer += Y * k } else { answer += X * k } } print(answer)