#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< >(b,vector(c,d)) #define vvv(a,b,c,d,e) vector > >(b,vv(a,c,d,e)) using ll = long long; using pii = pair; using vi = vector; using vll = vector; template struct ConvexHullTrick { deque > lines; Compare comp; ConvexHullTrick() :comp(Compare()) { } void addLine(Val slope, Val constant) { pair line(slope, constant); int n; while ((n = (int)lines.size())>=2) { Val a1, a2, a3, b1, b2, b3; tie(a1, b1) = lines[n - 2]; tie(a2, b2) = lines[n - 1]; tie(a3, b3) = line; if ((a1 - a2)*(b3 - b1) >(a1 - a3)*(b2 - b1))break; else lines.pop_back(); } lines.push_back(line); } Val query(Val x) { while ((int)lines.size() >= 2 && comp(f(x, lines[1]), f(x, lines[0]))) { lines.pop_front(); } return f(x, lines[0]); } Val f(Val x, pair line) { return x * line.first + line.second; } }; /* 解説のとおりの実装 ライブラリテスト */ int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int N, A, B, W; cin >> N >> A >> B >> W; vi D(N + 1); for (int i = 1; i <= N; ++i)cin >> D[i]; ConvexHullTrick > cht; cht.addLine(0, W); vll F(N + 1); F[0] = W; for (ll k = 1; k <= N; ++k) { F[k] = D[k] - (k - 1)*A + (k*k - k)*B / 2; F[k] += cht.query(k); cht.addLine(-B*k, F[k] + k*A + (k*k + k)*B / 2); } ll ans = LLONG_MAX; for (ll k = 0; k <= N; ++k) { smin(ans, F[k] - (N - k)*A + (N - k + 1)*(N - k)*B / 2); } cout << ans << endl; }