QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 128 MB مجموع النقاط: 100

#16031. Toy Packing

الإحصائيات

In August this year, Professor P is going to Beijing to watch the Olympics, but he cannot bear to leave behind his large collection of intellectual toys. Therefore, he decides to pack all his toys into boxes and ship them to Beijing, so that he can play with them while watching the games.

Professor P uses his Object Dimension Zipper (ODZ) to pack the toys. The ODZ can compress any object into one dimension, which can then be placed into a special one-dimensional container. Professor P has $n$ toys, numbered from $1$ to $n$. The one-dimensional length of the $i$-th toy after being processed by the ODZ is $c_i$. For the sake of organization, Professor P requires that the toys in any single one-dimensional container must have consecutive indices. Furthermore, if a container holds multiple toys, there must be $1$ unit of padding between any two adjacent toys. Formally, if toys from index $i$ to $j$ ($i < j$) are placed in a container, the length of the container will be:

$$l=j-i+\sum_{k=i}^{j} c_k$$

The cost of making a container depends on its length. According to Professor P's research, if the container length is $l$, the production cost is $(l-L)^2$, where $L$ is a constant derived from complex calculations. Professor P does not care about the number of containers and can manufacture containers of any length (even exceeding $L$), but he wants you to help him find the minimum total production cost.

Input

The first line contains two integers $n$ and $L$, separated by a space. The following $n$ lines each contain an integer $c_i$, representing the one-dimensional length of the $i$-th toy after being processed by the ODZ. It is guaranteed that $1\le n\le 50000$ and $1\le L,c_i\le 10^7$ for all $i$.

Output

Output a single integer representing the minimum production cost.

Examples

Input 1

5 4
3
4
2
1
4

Output 1

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.