# include # include #include # include #include #include #include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include #include #include #include #include #include #include //#include using namespace std; using LL = long long; using ULL = unsigned long long; long long MOD = 1000000000 + 7; //924844033 1000000000 + 9; constexpr long long INF = numeric_limits::max(); const double PI = acos(-1); #define fir first #define sec second #define thi third #define debug(x) cerr<<#x<<": "< Pll; typedef pair Dll; typedef pair> Ppll; typedef pair>> Pbll; typedef pair>> Pvll; typedef pair Vec2; struct Tll { LL first, second, third; }; struct Fll { LL first, second, third, fourth; }; typedef pair Ptll; #define rep(i,rept) for(LL i=0;i=0;i--) LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[330000],a[330020], b[330000]; string str, ss; bool f[220000]; char c[4000][4000]; int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } }; struct Edge { LL to, cost; }; struct edge { LL from, to, cost; }; vector>vec,rvec; vectored; vectorv; mapma; setst; void YN(bool f) { if (f) cout << "YES" << endl; else cout << "NO" << endl; } void yn(bool f) { if (f) cout << "Yes" << endl; else cout << "No" << endl; } template class ConvecHullTrick { private: // 直線群(配列) std::vector> lines; // 最小値(最大値)を求めるxが単調であるか bool isMonotonicX; // 最小/最大を判断する関数 std::function comp; public: // コンストラクタ ( クエリが単調であった場合はflag = trueとする ) ConvecHullTrick(bool flagX = false, std::function compFunc = [](T l, T r) {return l >= r; }) :isMonotonicX(flagX), comp(compFunc) { lines.emplace_back(0, 0); }; // 直線l1, l2, l3のうちl2が不必要であるかどうか bool check(std::pair l1, std::pair l2, std::pair l3) { if (l1 < l3) std::swap(l1, l3); return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first); } // 直線y=ax+bを追加する void add(T a, T b) { std::pair line(a, b); while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line)) lines.pop_back(); lines.emplace_back(line); } // i番目の直線f_i(x)に対するxの時の値を返す T f(int i, T x) { return lines[i].first * x + lines[i].second; } // i番目の直線f_i(x)に対するxの時の値を返す T f(std::pair line, T x) { return line.first * x + line.second; } // 直線群の中でxの時に最小(最大)となる値を返す T get(T x) { // 最小値(最大値)クエリにおけるxが単調 if (isMonotonicX) { 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 = -1, 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); } } }; ConvecHullTrick cht; int main() { LL A, B; cin >> n >> A >> B >> s; rep(i, n) { cin >> a[i]; } dp[0] = 0; cht.add(0, 0); for (LL i = 1; i < n + 1; i++) { dp[i] = a[i - 1] - A * (i - 1) + B * i * (i - 1LL) / 2 + cht.get(i); cht.add(-B * i, dp[i] + i * A + B * i * (i + 1LL) / 2); } ans = INF; rep(i, n + 1) { ans = min(ans, s+dp[i] - (n - i)*A + B * (n - i)*(n - i + 1) / 2); } cout << ans << endl; return 0; }