#P3650. [USACO1.3] 滑雪课程设计Ski Course Design
[USACO1.3] 滑雪课程设计Ski Course Design
Description
Farmer John has hills on his farm, each with an integer elevation between and . 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 , he must pay tax. Therefore, if he adjusts the hill elevations so that the difference between the highest and lowest elevations does not exceed , John can avoid paying the tax.
If changing a hill’s elevation by units costs units, what is the minimum total cost for John to ensure that the difference between the highest and lowest elevations does not exceed ? John only changes heights by integer amounts.
Input Format
The first line contains an integer , the number of hills.
Lines to each contain one integer. The integer on the -th line represents the elevation of the -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 , , and . He raises the hill of elevation to , costing . He lowers the hill of elevation to , also costing . Therefore, the total cost is .
Constraints: For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号