#Q193. 「一本通 5.6 练习 4」打印文章

「一本通 5.6 练习 4」打印文章

Description

Original Problem from: HDU 3507

Given NN words, each with a non-negative weight CiC_i, they are to be divided into consecutive segments. The cost of each segment is the square of the sum of the weights of the words in the segment plus a constant MM, i.e., (Ci)2+M(\sum C_i)^2 + M. The goal is to find an optimal segmentation that minimizes the total cost.

Input Format

The input contains multiple test cases. For each test case:
The first line contains two integers NN and MM.
The second line contains NN integers.

Output Format

Output a single integer representing the minimum total cost.

Sample 1

5 5
5 9 5 7 5

230

Constraints & Notes

For all test cases, 0N5×105, 0M10000\le N\le 5\times 10^5,\ 0\le M\le 1000.