#P17033. [NWERC 2020] Hot Springs

    ID: 17281 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>2020Special Judge排序构造ICPC

[NWERC 2020] Hot Springs

题目描述

Iceland is famous for its geothermal activity, which supplies the country with much of its electricity and heating. It is also a source of pleasure, in the form of hot springs.

Kalle is visiting one of Iceland's famous hot springs. It contains nn pools of water, where the iith one has temperature tit_i. Although staying in one of the warmer pools for a long time sure is relaxing, Kalle is on a very tight schedule and just wants a quick dip in each of the pools. As you may know, the nicest thing about hot baths is the contrast between hot and cold. Therefore, to get the most out of his stay, Kalle wants to find an ordering of the pools so that the difference in temperature between subsequent pools is increasing.

Given a sequence of pool temperatures t1,t2,…,tnt_1, t_2, \ldots, t_n, rearrange them into a new sequence t1′,t2′,…,tn′t'_1, t'_2, \ldots, t'_n such that for all 2≤i≤n−12 \le i \le n-1 it holds that

∣ti−1′−ti′∣≤∣ti′−ti+1′∣.|t'_{i-1} - t'_i| \le |t'_i - t'_{i+1}|.

输入格式

The input consists of:

  • One line with an integer nn (2≤n≤1052 \le n \leq 10^5), the number of pools.

  • One line with nn integers t1,…,tnt_1, \ldots, t_n (−\maxa≤ti≤\maxa-\maxa \leq t_i \leq \maxa for each ii), the temperatures in each of the nn pools.

输出格式

Output a rearrangement of the sequence satisfying the given requirement. If no solution exists, output "impossible". If there are multiple valid solutions, you may output any one of them.

3
1 3 4
4 3 1 
6
0 0 1 -1 -6 3
0 1 3 -1 -6 0