6925.Knuth Division

Time Limit: 1s Memory Limit: 512MB

Given an array of $n$ numbers, your task is to divide it into $n$ subarrays, each of which has a single element.

On each move, you may choose any subarray and split it into two subarrays. The cost of such a move is the sum of values in the chosen subarray.

What is the minimum total cost if you act optimally?

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the array size. The array elements are numbered $1,2,\dots,n$ .

The second line has $n$ integers $x_1,x_2,\dots,x_n$ : the contents of the array.

  • $1 \le n \le 5000$
  • $1 \le x_i \le 10^9$

Output Format(To the terminal/stdout)

Print one integer: the minimum total cost.

Sample Input

Copy
5
2 7 3 2 5
 \n
 · · · · \n

Sample Output

Copy
43
  \n
Source: CSES, Advanced Techniques, 2088

Submit

请先 登录

© 2025 FAQs