#P3195. [HNOI2008] 玩具装箱
[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 toys numbered . After compression, the one-dimensional length of the -th toy is .
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 through are placed in one container, the container length is .
The manufacturing cost of a container depends on its length. According to the professor’s study, if a container has length , its cost is , where is a constant. Professor P does not care about the number of containers; he can make containers of any length, even exceeding . He wants the total cost of all containers to be minimized.
Input Format
The first line contains two integers separated by a space, denoting and .
Lines to each contain one integer. Line contains the length of the -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, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号