416. Optimal Dartboard
Time limit per test: 0.25
Memory limit: 262144
A dartboard is a disc divided into n
segments, with each segment labeled with a distinct positive integer between 1 and n
. That integer indicates the score for hitting the segment. To make the game more interesting, the arrangement of numbers is chosen in such a way that the risk is maximized. The risk is estimated based on the differences in scores of adjacent segments.
We're studying the following 'double-layered' structure of segments in this problem:
is always even, and we split the disc into two layers of
parts along the circumference. We enumerate the segments in the following manner: the first segment is some outer segment, the second segment is the corresponding inner segment, the third segment is some adjacent outer segment, etc. An example of this enumeration is shown on the picture above.
The total risk is defined as the sum of squared differences between the scores of adjacent segments. If the value assigned to segment i
, then the risk is:R
(we assume an+1
in this formula).
You are to place the numbers from 1 through n
into the segments in such a way that the total risk R
The input file contains an even integer number n
(6 ≤ n
integer numbers: a1
, separated with single spaces. In case there are several possible solutions, output any.
2 9 7 4 6 5 3 8 10 1