#P7547. [BJWC2017] 太空飞船
[BJWC2017] 太空飞船
Description
This will be a ring-shaped spaceship, consisting of cabins in order. The designed length of the -th cabin is .
To provide energy for the spaceship, space energy absorbers need to be installed on the spaceship. According to authoritative theories, these absorbers should be distributed as evenly as possible over the surface of the spaceship. That is, Xiao Cheng needs to divide all cabins of the spaceship into parts (each part includes a consecutive segment of cabins), and assign one energy absorber to each part. Let the sum of cabin lengths in the -th part be ; then the variance should be minimized as much as possible.
However, this problem is too difficult for Xiao Cheng, who is already a senior undergraduate student. Can you help him finish the design? For convenience, output the product of the minimum variance and .
Input Format
The input consists of two lines.
The first line contains two integers .
The second line contains integers separated by spaces, representing the length of each cabin in order.
Output Format
Output one line with one integer, representing the product of the minimum variance and .
5 3
4 2 6 1 3
24
Hint
Constraints
For of the testdata, , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号