#include using namespace std; //#include //using namespace atcoder; using ll=long long; using Graph=vector>; #define MOD 1000000007 #define INF 1000000000000000000 #define MAX 1000000 //傾きが単調減少、xが単調増加 template class CHT{ struct Line{ T a,b; Line(ll a_,ll b_):a(a_),b(b_){} Line():a(0),b(0){} T get(T x){ return a*x+b; } }; private: deque deq; bool check(Line &l1,Line &l2,Line &l3) const{ return (l2.a-l1.a)*(l3.b-l2.b)<(l2.b-l1.b)*(l3.a-l2.a); } public: CHT(){} void insert(T a,T b){ Line l3(a,b); while(deq.size()>=2){ Line l2=*deq.rbegin(); Line l1=*(deq.rbegin()-1); if(check(l1,l2,l3)){ break; } deq.pop_back(); } deq.push_back(l3); } T get(T x){ while(deq.size()>=2){ Line l1=*begin(deq); Line l2=*(begin(deq)+1); if(l1.get(x)>N>>A>>B>>W; vector D(N); for(int i=0;i>D[i]; } vector dp(N+1,INF); dp[0]=W; CHT cht; cht.insert(0,dp[0]); for(ll i=0;i(ans,dp[i]+(N-i)*(N-i+1)*B/2-(N-i)*A); } //cout<