Workday Routine
Time limit2sMemory limit1024 MB
Find an integer first height and a common step so that the arithmetic progression has the smallest total absolute change from the given column heights.
- Level
Medium7 of 10
- Topics
- Binary search, Sorting, Math
- Solved
- No attempts yet
Statement
Foreman Pavel leads a crew building a concert hall to a new design by foreign architects. The main feature is a colonnade at the main entrance with columns. Unlike classical designs, each column has its own height, not equal to the height of the roof above the entrance. In the current plan, the heights are meters relative to the roof, from left to right. For example, height 10 means the column sticks out ten meters above the roof, and height -5 means there is a five meter gap between the top of the column and the roof.
Three days before the handover and opening, the architects arrived at the site and changed the design. The new requirement follows recent European fashion: the difference between any two adjacent columns must be the same. That is, for any integers and from 1 to , must hold. The exact height of each column does not matter. For technical reasons, each column height must be an integer number of meters relative to the roof.
Changing a column's height by meters, up or down, costs burles. Pavel asks you to choose a new height for each column so that the requirement holds and the total cost of the changes is as small as possible. Help him, or nobody will ever invite him to build foreign-designed buildings again.
Input
The first line contains an integer (), the number of columns in front of the building.
The second line contains integers (), the current column heights.
Output
Print two integers: the height of the first column and the difference between adjacent columns in an optimal plan.
The absolute values of both printed numbers must not exceed . It is guaranteed that an optimal answer satisfying this exists.
Hint
In the first test, no changes are needed, since there are only two columns and they satisfy the requirement automatically.
In the second test, the optimal heights are 3, 7, 11, 15, 19, and the total cost is .