/*想定TLE解法その1*/ #include using namespace std; typedef long long LL; typedef __int128 INT; /*cin高速化*/ struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init; ostream& operator<<(ostream &os,INT x){ LL y; y=x; assert(y==x); os << y; return os; } istream& operator>>(istream &is,INT& x){ LL y; is >> y; x = y; return is; } const INT INF = 1e24; int main() { INT N,A,B,W; /*input N,A,B,W*/ { cin >> N >> A >> B >> W; assert(1 <= N && N <= 300000); assert(0 <= A && A <= 1000000); assert(0 <= B && B <= 1000000); assert(0 <= W && W <= 1000000); } vector D(N); { for(auto& it : D){ cin >> it; assert(0 <= it && it <= 1000000); } } /*DP*/ vector dp(N+1,INF),nxt(N+1); dp[0] = W; for(int i = 0; i < N; i++){ nxt[0] = dp[N] + D[i]; for(int j = 0; j < N; j++){ nxt[0] = min(nxt[0],dp[j] + D[i]); nxt[j+1] = dp[j] - A + (j + 1) * B; } swap(dp,nxt); } /*output*/ INT res = INF; for(auto& it : dp) res = min(res,it); cout << res << endl; return 0; }