#P7840. 「C.E.L.U-03」重构

「C.E.L.U-03」重构

Description

Luo Siji has nn servers, and each server has a busyness value viv_i. Luo Siji will connect them together using n1n-1 network links, so each server will have a degree did_i, which is the number of connected links. The total running time of this server network is i=1ndi2vi\sum\limits_{i=1}^n d_i^2 v_i. Please minimize this value.

Input Format

The first line contains one integer, nn.
The second line contains nn integers, where the ii-th integer represents viv_i.

Output Format

The first line contains one integer, the answer.

4
2 3 4 4
28

Hint

Sample Explanation:
Connect three edges 12,14,231-2, 1-4, 2-3. The degrees are 2,2,1,12, 2, 1, 1, respectively.

Testdata ID nn Special Property
11 5\le5 None
232\sim 3 300\le300
454\sim 5 3×103\le3\times10^3
66 3×104\le3\times10^4 All viv_i are equal
787\sim 8 None
9109\sim 10 3×105\le3\times10^5

Constraints: For 100%100\% of the testdata, 1n3×1051\leq n\le3\times10^5 and 1vi1031\leq v_i\le10^3.

Translated by ChatGPT 5