

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
整数列 が与えられます。 頂点の木 に対して、 を以下で定めます。
- の頂点 の次数を とする。このとき、 とする。
として考えられる最小値を求めてください。
なお、制約下において答えが 未満となることは保証されています。
制約
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
4 3 2 5 2
出力例 1Copy
24
頂点 と頂点 を結ぶ辺、頂点 と頂点 を結ぶ辺、頂点 と頂点 を結ぶ辺からなるような木 を考えます。
このとき です。これが の最小値であることが証明できます。
入力例 2Copy
3 4 3 2
出力例 2Copy
15
入力例 3Copy
7 10 5 10 2 10 13 15
出力例 3Copy
128
Score : points
Problem Statement
You are given a sequence of integers . For a tree with vertices, define as follows:
- Let be the degree of vertex in . Then, .
Find the minimum possible value of .
The constraints guarantee the answer to be less than .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
4 3 2 5 2
Sample Output 1Copy
24
Consider a tree with an edge connecting vertices and , an edge connecting vertices and , and an edge connecting vertices and .
Then, . It can be proven that this is the minimum value of .
Sample Input 2Copy
3 4 3 2
Sample Output 2Copy
15
Sample Input 3Copy
7 10 5 10 2 10 13 15
Sample Output 3Copy
128