#P3650. [USACO1.3] Ski Course Design

[USACO1.3] Ski Course Design

题目描述

Farmer John has NN hills on his farm (1N10001 \le N \le 1000), each with an integer elevation in the range 0..1000..100. In the winter, since there is abundant snow on these hills, Farmer John routinely operates a ski training camp.

Unfortunately, Farmer John has just found out about a new tax that will be assessed next year on farms used as ski training camps. Upon careful reading of the law, however, he discovers that the official definition of a ski camp requires the difference between the highest and lowest hill on his property to be strictly larger than 1717. Therefore, if he shortens his tallest hills and adds mass to increase the height of his shorter hills, Farmer John can avoid paying the tax as long as the new difference between the highest and lowest hill is at most 1717.

If it costs x2x^2 units of money to change the height of a hill by xx units, what is the minimum amount of money Farmer John will need to pay? Farmer John can change the height of a hill only once, so the total cost for each hill is the square of the difference between its original and final height. Farmer John is only willing to change the height of each hill by an integer amount.

输入格式

  • Line 1: The integer NN.
  • Lines 2..N+1N+1: Each line contains the elevation of a single hill.

输出格式

  • Line 1: The minimum amount Farmer John needs to pay to modify the elevations of his hills so the difference between largest and smallest is at most 1717 units.
5
20
4
1
24
21
18

提示

Input Details

Farmer John's farm has 55 hills, with elevations 11, 44, 2020, 2121, and 2424.

Output Details

Farmer John keeps the hills of heights 44, 2020, and 2121 as they are. He adds mass to the hill of height 11, bringing it to height 44 (cost = 32=93^2 = 9). He shortens the hill of height 2424 to height 2121, also at a cost of 32=93^2 = 9.

USACO Training Section 1.3