#include using namespace std; #define rep(i,a,b) for(int i=a;i struct CHT { struct line { T slope, xterm; inline T get(const int x) const { return slope * x + xterm; } }; deque lines; inline ld area(const line& a, const line& b, const line& c) { ld ax = (b.slope - a.slope); ld bx = (c.xterm - a.xterm); ld ay = (c.slope - a.slope); ld by = (b.xterm - a.xterm); return ax * bx - ay * by; } inline bool cw(const line& a, const line& b, const line& c) { return area(a, b, c) < 0; } void add(T a, T b) { line l; l.slope = a, l.xterm = b; while (lines.size() > 1 && cw(lines[lines.size() - 2], lines[lines.size() - 1], l)) lines.pop_back(); if (lines.size() == 1) { if (lines.front().xterm > l.xterm) lines.push_back(l); } else lines.push_back(l); } T get(int x) { if (lines.empty()) return 0; while (lines.size() > 1 && lines[0].get(x) > lines[1].get(x)) lines.pop_front(); return lines[0].get(x); } }; //----------------------------------------------------------------------------------- typedef long long ll; #define INF 1LL<<60 int N, A, B, W; int D[301010]; //----------------------------------------------------------------------------------- ll dp[301010]; int main() { cin >> N >> A >> B >> W; rep(i, 0, N) scanf("%d", &D[i]); /* Naive dp[0] = W; rep(i, 1, N + 1) { dp[i] = INF; rep(j, 0, i) { ll w = dp[j]; w -= 1LL * A * (i - j - 1); w += 1LL * (i - j - 1) * (i - j) / 2 * B; dp[i] = min(dp[i], w); } dp[i] += D[i - 1]; } */ // Optimized CHT cht; dp[0] = W; cht.add(0, W); rep(i, 1, N + 1) { dp[i] = cht.get(i) - 1LL * (i - 1) * A + (1LL * (i - 1) * i) / 2 * B + D[i - 1]; cht.add(-1LL * B * i, dp[i] + 1LL * A * i + (1LL * i * i + i) / 2 * B); } ll ans = INF; rep(i, 0, N + 1) { ll w = dp[i]; int n = N - i; w -= 1LL * A * n; w += 1LL * n * (n + 1) / 2 * B; ans = min(ans, w); } cout << ans << endl; }