#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
ll x = 0,f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
ll n, L, c[50005], a[50005], b[50005], dp[50005];
struct node{
ll x, y;
}q[50005];
int main(){
n = read(), L = read();
for(int i = 1; i <= n; ++i){
c[i] = read(), c[i] += c[i - 1];
}
for(int i = 1; i <= n; ++i){
a[i] = c[i] + i;
b[i] = a[i] + L + 1;
}
int l = 1, r = 0;
q[++r] = {0, 0};
for(int i = 1; i <= n; ++i){
while(l < r && q[l + 1].y - q[l].y < 2 * a[i] * (q[l + 1].x - q[l].x)) l++;
dp[i] = q[l].y - 2 * a[i] * q[l].x + a[i] * a[i];
node now = {b[i], dp[i] + b[i] * b[i]};
while(l < r && (now.y - q[r].y) * (q[r].x - q[r - 1].x) < (q[r].y - q[r - 1].y) * (now.x - q[r].x)) r--;
q[++r] = now;
}
printf("%lld\n", dp[n]);
return 0;
}
//dp_i = dp_(j-1) + a_i^2 + b_j^2 - 2*a_i*b_j;
样例一直输出 16,求调,谢谢/bx