-->
当前位置:首页 > 题库

PROGRAMMING:Repair Ranch

Luz5年前 (2021-05-10)题库485
The farmer wanted to repair a fence in the pasture. He measured the fence and found that he needed $$n $$pieces of wood, each piece of wood was an integer of $$L_ So he bought a very long piece of wood that can be sawn into $$n $, that is, the length of the wood is $$L_ The sum of I $$.
But the farmer didn't have a saw, and the reward for having someone saw the wood was proportional to the length of the wood. For the sake of simplicity, we may as well set the reward equal to the length of the sawn wood. For example, if you want to saw a piece of wood with a length of 20 into three sections with a length of 8, 7 and 5, it will cost 20 to saw the wood for the first time and cut the wood into 12 and 8; The second sawing cost 12, and the total cost of sawing 12 length wood into 7 and 5 is 32. If the wood is sawn into 15 and 5 for the first time, it will cost 15 for the second time, and the total cost is 35 (more than 32).
Write a program to help farmers calculate the minimum cost of sawing wood into $$n $.
###Input format:
Input first gives a positive integer $$n $$($$Le 10 ^ 4 $$), which means to saw the wood into $$n $$. The second line gives $$n $$positive integers ($$$Le 50 $$), indicating the length of each block.
###Output format:
Output an integer, that is, the minimum cost of sawing wood into $$n $.
###Input example:
```in
eight
4 5 1 2 1 3 1 1
```
###Output example:
```out
forty-nine
```






answer:If there is no answer, please comment