QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 2048 MB 満点: 100

#2367. 温泉

統計

冰岛以其地热活动而闻名,这为该国提供了大量的电力和供暖。它也是一种享受,以温泉的形式存在。

Blue Lagoon by Andy Wang, Unsplash

Kalle 正在参观冰岛著名的温泉之一。这里有 $n$ 个水池,其中第 $i$ 个水池的温度为 $t_i$。虽然在较暖的水池中长时间停留确实很放松,但 Kalle 的行程非常紧凑,他只想在每个水池中快速泡一下。如你所知,温泉最棒的地方在于冷热交替。因此,为了充分利用他的行程,Kalle 想要找到一种水池的排列顺序,使得相邻水池之间的温差是递增的。

给定一个水池温度序列 $t_1, t_2, \dots, t_n$,请将其重新排列为一个新的序列 $t'_1, t'_2, \dots, t'_n$,使得对于所有 $2 \le i \le n - 1$,满足: $$|t'_{i-1} - t'_i| \le |t'_i - t'_{i+1}|$$

输入包含: 一行一个整数 $n$ ($2 \le n \le 10^5$),表示水池的数量。 一行 $n$ 个整数 $t_1, \dots, t_n$ (对于每个 $i$,$-10^5 \le t_i \le 10^5$),表示每个水池的温度。

输出满足给定要求的序列重排。如果不存在解决方案,输出 “impossible”。如果有多个有效的解决方案,你可以输出其中任意一个。

样例

输入格式 1

3
1 3 4

输出格式 1

4 3 1

输入格式 2

6
0 0 1 -1 -6 3

输出格式 2

0 1 3 -1 -6 0

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.