#include<bits/stdc++.h>
#define qq 51234
using namespace std;
long long N,L,C[qq],Toy,Tony,f,s,w,x[qq],y[qq];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>N>>L;
for(int i=1;i<=N;i++)cin>>C[i];
for(int i=1;i<=N;i++){
s+=C[i]+1,w=s-L-1;
if(Toy>=Tony)Toy=Tony;
else{
while(Toy<Tony&&(1.0*(y[Toy+1]-y[Toy])
/(x[Toy+1]-x[Toy]))<(w<<1))Toy++;
}
f=y[Toy]-2*w*x[Toy]+w*w;
x[Tony+1]=s;
y[Tony+1]=f+s*s;
for(;Tony&&(1.0*(y[Tony]-y[Tony-1])
/(x[Tony]-x[Tony-1]))
>(1.0*(y[Tony+1]-y[Tony-1])
/(x[Tony+1]-x[Tony-1]))
;Tony--){
swap(x[Tony],x[Tony+1]);
swap(y[Tony],y[Tony+1]);
}
Tony++;
}
cout<<f;
}
P3195 [HNOI2008] 玩具装箱
最新推荐文章于 2024-11-05 21:58:11 发布