#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define int long long #define double long double typedef vector VI; typedef pair pii; typedef vector VP; typedef vector VS; typedef priority_queue PQ; templatebool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i, greater > q2; int N, K, X, Y; VI A; int check(int M) { //cout << M << endl; int res = Y * M; VI tmp = A; REP(i, N) { //cout << A[i] << " "; tmp[i] -= M * K; if (tmp[i] > 0)res += ((tmp[i] + K - 1) / K) * X; } //cout << M << " " << res << endl; //cout << endl; return res; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K >> X >> Y; A.resize(N); REP(i, N) { cin >> A[i]; A[i]--; } int L = 0, R = INF + 10; while (R - L > 2) { //cout << L << " " << R << endl; int t1 = (L * 2 + R) / 3; int t2 = (L + R * 2) / 3; if (check(t1) < check(t2)) R = t2; else L = t1; } int ans = LLINF; //L = max(0LL, L - 5); //R += 5; //FOR(i, L, R)chmin(ans, check(i)); cout << min({ check(L),check(L + 1), check(R) }) << endl; //cout << ans << endl; return 0; }