#include #include #include using namespace std; using int64 = long long; int main() { int64 n,k,x,y; cin >> n >> k >> x >> y; vector a(n,0LL); for (int i=0; i> a[i]; a[i]--; } sort(a.rbegin(), a.rend()); int64 ans = 0; int64 cnt = 0; while(!empty(a)) { if (a.size()*x >= y) { int64 e = (a.back()-cnt*k+k-1) / k; ans += y * e; cnt += e; while(!empty(a) && a.back() - cnt*k <= 0) a.pop_back(); } else { int64 e = (a.back() - cnt*k +k-1) / k; ans += x * e; a.pop_back(); } } cout << ans << endl; }