1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4 #include<cmath>
5 #include<queue>
6
7 #define maxn 50001
8
9 using namespace std;
10
11 long long sum[maxn],M[maxn],f[maxn];
12
13 int n,L,que[50001],head=1,tail=1;
14
15 double K(int x,int y){return ((double)f[x]+sum[x]*sum[x]-f[y]-sum[y]*sum[y])/(double)(sum[x]-sum[y])*1.0;}
16
17 void DP()
18 {
19 for(int i=1;i<=n;i++)
20 {
21 while(head<tail&&K(que[head],que[head+1])<=2*M[i])head++;
22 int sb=que[head];
23 f[i]=f[sb]+(M[i]-sum[sb])*(M[i]-sum[sb]);
24 while(head<tail&&K(que[tail],i)<=K(que[tail-1],que[tail]))tail--;
25 que[++tail]=i;
26 }
27 printf("%lld",f[n]);
28 }
29
30 int main()
31 {
32 freopen("1010.in","r",stdin);
33 scanf("%d%d",&n,&L);
34 for(int i=1;i<=n;i++)
35 scanf("%lld",&sum[i]),sum[i]+=sum[i-1]+1,M[i]=sum[i]-L-1;
36 DP();
37 return 0;
38 }