#d2844. 切割
切割
Cutting
Problem Source
Original problem: [NOIP 2004 Advanced Group] Merging Fruits / [USACO06NOV] Fence Repair G (https://www.luogu.com.cn/problem/P1090)
A data-strengthened version requiring an solution: (https://www.luogu.com.cn/problem/P6033) ()
Problem Description
There is a wooden board of total length that needs to be cut into pieces of lengths .
Each cut incurs a cost equal to the length of the board being cut.
Find the minimum total cost to cut the board into the pieces above.
Input Format
The first line contains a positive integer .
The second line contains positive integers: .
Output Format
Output one positive integer: the minimum cost.
Sample Input
5
5 3 4 4 4
Sample Output
47
Constraints
For all test data: .