#include using namespace std; using Int8 = int8_t; using Int16 = int16_t; using Int32 = int32_t; using Int64 = int64_t; using Int128 = __int128_t; using Word8 = uint8_t; using Word16 = uint16_t; using Word32 = uint32_t; using Word64 = uint64_t; using Word128 = __uint128_t; using Int = int_fast64_t; using Word = uint_fast64_t; using VI = vector; using VW = vector; using VVI = vector; using VVW = vector; using F32 = float; using F64 = double; using F80 = long double; using PII = pair; using PWW = pair; using VPII = vector; using VPWW = vector; using VS = vector; using VVS = vector; using VB = vector; using VVB = vector; #define rep(i,n) for(Int i=0,i##_len=(n); i class ConvexHullTrick { private: vector> lines; bool is_monotonic; public: ConvexHullTrick(bool flag = false) : is_monotonic(flag) { lines.emplace_back(0, 0); } bool check(pair l1, pair l2, pair l3) { return (l2.first - l1.first) * (l3.second - l2.second) >= (l2.second - l1.second) * (l3.first - l2.first); } void add(pair l) { pair line(l); while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line)) lines.pop_back(); lines.emplace_back(line); } void add(T a, T b) { pair line(a, b); add(line); } T f(int i, T x) { return lines[i].first * x + lines[i].second; } T get(T x, function comp = [](T l, T r) { return l >= r; }) { if (is_monotonic) { static int head = 0; while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x))) ++head; return f(head, x); } else { int low = 0, high = lines.size() - 1; while (high - low > 1) { int mid = (high - low) / 2; (comp(f(mid, x), f(mid + 1, x)) ? low : high) = mid; } return f(high, x); } } }; /** * yukicoder No409. ダイエット **/ int main () { Int N, A, B, W; cin >> N >> A >> B >> W; VI d(N); rep(i,N) cin >> d[i]; ConvexHullTrick cht(true); Int dp[300005]; dp[0] = 0; Range(i,1,N) { dp[i] = cht.get(i - 1) - (i - 1) * A + ((Int)(i - 1) * i) / 2 * B + d[i - 1]; cht.add(- i * B, dp[i] + i * A + (Int)(i - 1) * i / 2 * B); } Int ans = 1LL<<30; rep(i,(N + 1)) { ans = min(ans, dp[i] + (-(N - i) * A + (N - i) * (N - i + 1) / 2 * B)); } cout << ans + W << endl; }