#Q149. 「一本通 5.1 例 1」石子合并
「一本通 5.1 例 1」石子合并
Description
Arrange piles of stones around a circular playground. The goal is to merge them into a single pile in an orderly manner. The rule is that only two adjacent piles can be merged at a time, and the number of stones in the new pile is recorded as the score for that merge.
Write a program that reads the number of piles and the number of stones in each pile, and performs the following calculations:
- Choose a merging strategy that maximizes the total score after merges.
- Choose a merging strategy that minimizes the total score after merges.
Input Format
The first line of input contains an integer , representing the number of piles of stones.
The second line contains integers, representing the number of stones in each pile.
Output Format
The output consists of two lines:
The first line contains the minimum total merge score,
The second line contains the maximum total merge score.
Sample 1
4
4 5 9 4
43
54
Data Range and Hint
For of the data, .