Megha is one of the most talented architects in the industry. The government is planning to construct a new line of skyscrapers and has tasked Megha with designing it's layout. The following are the requirements which have been specified:
Note: If the number of skyscrapers is even, the main building can be at either of the centers.
To make the arrangement look good, Megha wants to minimize the irregularity in heights between consecutive skyscrapers. Formally, she wants to minimize the sum of the absolute height differences of adjacent skyscrapers. Your task is to help her find the optimal arrangement which satisfies the given requirements.
One optimal way to line up is 17, 12, 13, 10, 11 making the sum of the absolute differences 5 + 1 + 3 + 1 = 10.