1 /**************************************************************
2 Problem: 1010
3 User: Jstyle
4 Language: C++
5 Result: Accepted
6 Time:176 ms
7 Memory:2844 kb
8 ****************************************************************/
9
10 #include <iostream>
11 #include <algorithm>
12 #include <cstring>
13 #include <cstdlib>
14 #include <cstdio>
15 #include <bitset>
16 #include <vector>
17 #include <queue>
18 #include <stack>
19 #include <cmath>
20 #include <list>
21 #include <set>
22 #include <map>
23 #define rep(i,a,b) for(int i = a;i <= b;++ i)
24 #define per(i,a,b) for(int i = a;i >= b;-- i)
25 #define mem(a,b) memset((a),(b),sizeof((a)))
26 #define FIN freopen("in.txt","r",stdin)
27 #define FOUT freopen("out.txt","w",stdout)
28 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
29 #define mid ((l+r)>>1)
30 #define ls (id<<1)
31 #define rs ((id<<1)|1)
32 #define N 50005
33 #define INF 0x3f3f3f3f
34 #define INFF ((1LL<<62)-1)
35 typedef long long LL;
36 using namespace std;
37
38 LL n, q[N],L, a[N], dp[N], sum[N];
39
40 double cal(int x, int y){
41 return (dp[x]-dp[y]+sum[x]*sum[x]-sum[y]*sum[y])*1.0/(sum[x]-sum[y]);
42 }
43 void Init(){
44 mem(dp, 0);
45 mem(sum, 0);
46 }
47 int main()
48 {IO;
49 //FIN;
50 while(cin >> n >> L){
51 Init();
52 rep(i, 1, n){
53 cin >> a[i];
54 sum[i] = sum[i-1] + a[i] + 1;
55 }
56 int l = 0, r = 0;
57 rep(i, 1, n){
58 while(l < r && cal(q[l], q[l+1]) <= 2*(sum[i]-1-L)) l++;
59 int id = q[l];
60 dp[i] = dp[id]+(sum[i]-sum[id]-1-L)*(sum[i]-sum[id]-1-L);
61 while(l < r && cal(q[r], i) < cal(q[r-1], q[r])) r--;
62 q[++r] = i;
63 }
64 cout << dp[n] << endl;
65 }
66 return 0;
67 }