#P3195. [HNOI2008] 玩具装箱

    ID: 2244 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2008单调队列湖南斜率优化

[HNOI2008] 玩具装箱

Description

Professor P is going to watch the Olympics, but he cannot part with his toys, so he decides to ship all his toys to Beijing. He uses his own compressor, which can compress any item into a lump and then place it into a special one-dimensional container.

Professor P has nn toys numbered 1n1 \cdots n. After compression, the one-dimensional length of the ii-th toy is CiC_i.

To organize them conveniently, Professor P requires:

  • The toy indices in a one-dimensional container must be consecutive.
  • Additionally, if a container holds more than one toy, a unit-length filler must be added between any two adjacent toys. Formally, if toys ii through jj are placed in one container, the container length is x=ji+k=ijCkx=j-i+\sum\limits_{k=i}^{j}C_k.

The manufacturing cost of a container depends on its length. According to the professor’s study, if a container has length xx, its cost is (xL)2(x-L)^2, where LL is a constant. Professor P does not care about the number of containers; he can make containers of any length, even exceeding LL. He wants the total cost of all containers to be minimized.

Input Format

The first line contains two integers separated by a space, denoting nn and LL.

Lines 22 to (n+1)(n + 1) each contain one integer. Line (i+1)(i + 1) contains the length CiC_i of the ii-th toy.

Output Format

Output a single integer on one line, the minimum possible total cost of all containers.

5 4
3
4
2
1
4
1

Hint

For all test points, 1n5×1041 \leq n \leq 5 \times 10^4, 1L1071 \leq L \leq 10^7, 1Ci1071 \leq C_i \leq 10^7.

Translated by ChatGPT 5