推出来式子以后斜率优化水过去就完事了
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#define inf 0x3f3f3f3f
#define LL long long int
using namespace std;
const int maxn=; inline LL rd(){
LL x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
} int N;
LL f[maxn],x[maxn],s[maxn],A,B,C;
int q[maxn],head,tail; inline LL pw2(LL x){return x*x;} inline bool judge1(int j1,int j2,int i){
return (f[j1]+A*pw2(s[j1])-f[j2]-A*pw2(s[j2]))>*A*s[i]*(s[j1]-s[j2]);
}
inline bool judge2(int j1,int j2,int j3,int i){
return (f[j1]+A*pw2(s[j1])-f[j2]-A*pw2(s[j2]))*(s[j2]-s[j3])<
(f[j2]+A*pw2(s[j2])-f[j3]-A*pw2(s[j3]))*(s[j1]-s[j2]);
} int main(){
//freopen("3628.in","r",stdin);
int i,j,k;
N=rd();A=rd();B=rd();C=rd();
for(i=;i<=N;i++) x[i]=rd(),s[i]=s[i-]+x[i];
LL ans=;
tail=head=;q[]=;
for(i=;i<=N;i++){
while(head<tail&&!judge1(q[head],q[head+],i)) head++;
f[i]=f[q[head]]+A*pw2(s[i]-s[q[head]])+C;
while(head<tail&&judge2(q[tail-],q[tail],i,i)) tail--;
q[++tail]=i;
}printf("%lld\n",f[N]+B*s[N]);
return ;
}