#include //#include using namespace std; // using namespace atcoder; // using mint = modint1000000007; // const int mod = 1000000007; // using mint = modint998244353; // const int mod = 998244353; // const int INF = 1e9; const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, l, r) for (int i = (l); i < (r); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rrep2(i, l, r) for (int i = (r)-1; i >= (l); --i) #define all(x) (x).begin(), (x).end() #define allR(x) (x).rbegin(), (x).rend() #define P pair template inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return true; } return false; } #ifndef KWM_T_DATA_STRUCTURE_CONVEX_HULL_TRICK_ADD_MONOTONE_HPP #define KWM_T_DATA_STRUCTURE_CONVEX_HULL_TRICK_ADD_MONOTONE_HPP #include #include #include #include namespace kwm_t::data_structure { /** * @brief Convex Hull Trick (Add Monotone) * * 典型用途: * - 直線集合に対する最小値 / 最大値クエリ * - 傾きが単調に追加される場合のDP最適化 * * 計算量: * - add: amortized O(1) * - query: O(log N) * - monotone query: O(1) * verified * https://atcoder.jp/contests/abc228/submissions/75110284 * https://atcoder.jp/contests/abc289/submissions/75110314 */ template struct ConvexHullTrickAddMonotone { std::deque> H; ConvexHullTrickAddMonotone() = default; bool empty() const { return H.empty(); } void clear() { H.clear(); } inline int sgn(T x) { return x == 0 ? 0 : (x < 0 ? -1 : 1); } using D = long double; inline bool check(const std::pair &a, const std::pair &b, const std::pair &c) { if (b.second == a.second || c.second == b.second) return sgn(b.first - a.first) * sgn(c.second - b.second) >= sgn(c.first - b.first) * sgn(b.second - a.second); return D(b.first - a.first) * sgn(c.second - b.second) / D(std::abs(b.second - a.second)) >= D(c.first - b.first) * sgn(b.second - a.second) / D(std::abs(c.second - b.second)); } void add(T a, T b) { if (!isMin) a *= -1, b *= -1; std::pair line(a, b); if (empty()) { H.emplace_front(line); return; } if (H.front().first <= a) { if (H.front().first == a) { if (H.front().second <= b) return; H.pop_front(); } while (H.size() >= 2 && check(line, H.front(), H[1])) H.pop_front(); H.emplace_front(line); } else { assert(a <= H.back().first); if (H.back().first == a) { if (H.back().second <= b) return; H.pop_back(); } while (H.size() >= 2 && check(H[H.size() - 2], H.back(), line)) H.pop_back(); H.emplace_back(line); } } inline T get_y(const std::pair &a, const T &x) { return a.first * x + a.second; } T query(T x) { assert(!empty()); int l = -1, r = (int)H.size() - 1; while (l + 1 < r) { int m = (l + r) >> 1; if (get_y(H[m], x) >= get_y(H[m + 1], x)) l = m; else r = m; } if (isMin) return get_y(H[r], x); return -get_y(H[r], x); } T query_monotone_inc(T x) { assert(!empty()); while (H.size() >= 2 && get_y(H.front(), x) >= get_y(H[1], x)) H.pop_front(); if (isMin) return get_y(H.front(), x); return -get_y(H.front(), x); } T query_monotone_dec(T x) { assert(!empty()); while (H.size() >= 2 && get_y(H.back(), x) >= get_y(H[H.size() - 2], x)) H.pop_back(); if (isMin) return get_y(H.back(), x); return -get_y(H.back(), x); } }; } // namespace kwm_t::data_structure #endif // KWM_T_DATA_STRUCTURE_CONVEX_HULL_TRICK_ADD_MONOTONE_HPP int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, a, b, w; cin >> n >> a >> b >> w; vectord(n); rep(i, n)cin >> d[i]; vectordp(n + 1); kwm_t::data_structure::ConvexHullTrickAddMonotone cht; cht.add(0, 0); rep2(i, 1, n + 1) { dp[i] = cht.query(i - 1) - (long long)a*(i - 1); dp[i] += (long long)(i - 1) * i / 2 * b + d[i - 1]; cht.add(-(long long)i * b, dp[i] + (long long)i * a + ((long long)i * i - i) / 2 * b); } long long ans = LINF; rep(i, n + 1) { long long add = -1 * ((long long)n - i) *a + ((long long)n - i) *(n - i + 1) / 2 * b; chmin(ans, dp[i] + add); } cout << ans + w << endl; return 0; }