1 #include <bits/stdc++.h>
2 using namespace std;
3 long long f[50005], c[50005];
4 int q[50005];
5
6 double pow(long long x)
7 {
8 return 1.0 * x * x;
9 }
10
11 double slope(int x)
12 {
13 return (f[q[x]] + pow(c[q[x]]) - f[q[x - 1]] - pow(c[q[x - 1]])) / (c[q[x]] - c[q[x - 1]]);
14 }
15
16 int main()
17 {
18 int n, l, front = 0, back;
19 cin >> n >> l;
20 for(int i = 1; i <= n; ++i)
21 {
22 cin >> c[i];
23 c[i] += c[i - 1] + 1;
24 }
25 ++l;
26 q[back = 1] = 0;
27 for(int i = 1; i <= n; ++i)
28 {
29 while(front + 1 < back && slope(front + 2) <= 2 * (c[i] - l))
30 ++front;
31 int j = q[front + 1];
32 f[i] = f[j] + (long long)pow(c[i] - c[j] - l);
33 q[++back] = i;
34 while(front + 1 < back && slope(back - 1) >= slope(back))
35 q[--back] = i;
36 }
37 cout << f[n] << endl;
38 return 0;
39 }