#P3650. [USACO1.3] 滑雪课程设计Ski Course Design

[USACO1.3] 滑雪课程设计Ski Course Design

Description

Farmer John has nn hills on his farm, each with an integer elevation between 00 and 100100. In winter, thanks to the abundant snow, he often runs ski training camps.

Unfortunately, John has just learned of a new tax law related to ski training camps that will take effect next year. After carefully reading the law, he found that if the difference between the highest and lowest hill elevations in a camp exceeds 1717, he must pay tax. Therefore, if he adjusts the hill elevations so that the difference between the highest and lowest elevations does not exceed 1717, John can avoid paying the tax.

If changing a hill’s elevation by xx units costs x2x^2 units, what is the minimum total cost for John to ensure that the difference between the highest and lowest elevations does not exceed 1717? John only changes heights by integer amounts.

Input Format

The first line contains an integer nn, the number of hills.

Lines 22 to (n+1)(n + 1) each contain one integer. The integer on the ii-th line aia_i represents the elevation of the ii-th hill.

Output Format

Output a single integer, the total cost John must pay to adjust the hill elevations.

5
20
4
1
24
21
18

Hint

Sample 1 explanation: John keeps the hills of elevations 44, 2020, and 2121. He raises the hill of elevation 11 to 44, costing 32=93^2 = 9. He lowers the hill of elevation 2424 to 2121, also costing 32=93^2 = 9. Therefore, the total cost is 9+9=189 + 9 = 18.

Constraints: For 100%100\% of the testdata, 1n10001 \le n \le 1000, 0ai1000 \le a_i \le 100.

Translated by ChatGPT 5