#P2308. 添加括号
添加括号
Description
Now we add pairs of parentheses. The additions are performed according to the parentheses order, producing intermediate sums. Find the way to add parentheses that minimizes the total of the intermediate sums.
Input Format
Two lines.
The first line contains an integer .
The second line contains positive integers , each not exceeding .
Output Format
Output 3 lines.
The first line is the parenthesization.
The second line is the final total of the intermediate sums.
The third line contains the intermediate sums, output from inner to outer and from left to right.
4
4 1 2 3
(4+((1+2)+3))
19
3 6 10
Hint
Sample Explanation
See the Background.
Constraints
For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号