아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Hot Springs

시간 제한1초메모리 제한1024 MB

요약
연속한 두 수의 차의 절댓값이 커지도록 n개의 온도를 재배열하고, 불가능하면 impossible을 출력한다.
난이도

보통10점 중 7점

유형
그리디, 정렬
정답자
아직 제출이 없습니다

문제

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 t_it\_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,…,t_nt\_1, t\_2, \dots, t\_n, rearrange them into a new sequence t′_1,t′_2,…,t′_nt'\_1, t'\_2, \dots, t'\_n such that for all 2≤i≤n−12 \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 nn (2≤n≤ 1052 \le n \leq  10^5), the number of pools.
  • One line with nn integers t_1,…,t_nt\_1, \ldots, t\_n (−105≤t_i≤105-10^5 \leq t\_i \leq 10^5 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.

예제2

  1. 예제 1

    입력
    3
    1 3 4
    
    예상 출력
    4 3 1
    
  2. 예제 2

    입력
    6
    0 0 1 -1 -6 3
    
    예상 출력
    0 1 3 -1 -6 0