#Q190. 「一本通 5.6 练习 1」玩具装箱
「一本通 5.6 练习 1」玩具装箱
Description
Original source: HNOI 2008
Professor P is going to the Olympics, but he can't bear to part with his toys, so he decides to transport all of them to Beijing.
He uses his own compressor to pack them. This compressor can transform any item into one-dimensional form and place it into a special one-dimensional container. Professor P has N toys numbered from to . After compression, the -th toy has a length of .
For ease of organization, Professor P requires:
- In a one-dimensional container, the toy numbers must be consecutive;
- If a one-dimensional container holds multiple toys, a unit-length filler must be added between each pair of toys. Formally, if toys numbered from to are placed in the same container, the container length must be at least .
The cost of making a container depends on its length. According to the professor's research, if the container length is , the production cost is , where is a constant.
Professor P doesn't care about the number of containers; he can make containers of any length, even exceeding . Find the minimum cost.
Input Format
The first line contains two integers and ;
The next lines each contain an integer .
Output Format
Output the minimum cost.
Sample 1
5 4
3
4
2
1
4
1
Data Range and Hints
For all data, , .