Logo
(追記) (追記ここまで)

21344번 - Hot Springs 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB20215513777.841%

문제

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 $n$ pools of water, where the $i$th one has temperature $t_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 $t_1, t_2, \dots, t_n,ドル rearrange them into a new sequence $t'_1, t'_2, \dots, t'_n$ such that for all 2ドル \leq i \leq n-1$ it holds that \[ |t'_{i-1} - t'_i| \leq |t'_i - t'_{i+1}|. \]

입력

The input consists of:

  • One line with an integer $n$ (2ドル \le n \leq 10^5$), the number of pools.
  • One line with $n$ integers $t_1, \ldots, t_n$ ($-10^5 \leq t_i \leq 10^5$ for each $i$), the temperatures in each of the $n$ 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.

제한

예제 입력 1

3
1 3 4

예제 출력 1

4 3 1

예제 입력 2

6
0 0 1 -1 -6 3

예제 출력 2

0 1 3 -1 -6 0

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2020 H번

  • 문제를 만든 사람: Timon Knigge
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /