CF1131C.Birthday

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Cowboy Vlad has a birthday today! There are nn children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.

Formally, let's number children from 11 to nn in a circle order, that is, for every ii child with number ii will stand next to the child with number i+1i+1, also the child with number 11 stands next to the child with number nn. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.

Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.

今天是牛仔弗拉德的生日!共有 nn 个孩子来参加庆祝活动。为了向弗拉德问好,孩子们决定围成一个圆圈站在他周围。到场的孩子中既有高个子也有矮个子,因此如果他们随意围成一圈,就可能出现一个高个子和一个矮个子相邻站立的情况,导致他们难以牵手。因此,孩子们希望以某种方式围成一个圆圈,使得任意两个相邻孩子身高之差的最大值尽可能小。

形式化地,我们将圆圈中的孩子按顺时针(或逆时针)顺序编号为 11 到 nn,即对每个 ii,编号为 ii 的孩子与编号为 i+1i+1 的孩子相邻;同时,编号为 11 的孩子也与编号为 nn 的孩子相邻。我们定义该圆圈的“不适度”(discomfort)为所有相邻孩子身高之差的绝对值中的最大值。

请帮助孩子们找出一种排列方式,使得最终的不适度最小。

输入格式

The first line contains a single integer nn (2≤n≤1002 \leq n \leq 100) — the number of the children who came to the cowboy Vlad's birthday.

The second line contains integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) denoting heights of every child.

第一行包含一个整数 nn(2≤n≤1002 \leq n \leq 100)—— 表示来到牛仔弗拉德生日聚会的小朋友人数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9),表示每个小朋友的身高。

输出格式

Print exactly nn integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.

If there are multiple possible answers, print any of them.

恰好输出 nn 个整数——即孩子们的身高,按他们应在圆圈中站立的顺序排列。你可以从任意一个孩子开始输出该圆圈。

若存在多个可能的答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    5
    2 1 1 3 2

    输出#1

    1 2 3 2 1
  • 输入#2

    3
    30 10 20

    输出#2

    10 20 30

说明/提示

In the first example, the discomfort of the circle is equal to 11, since the corresponding absolute differences are 11, 11, 11 and 00. Note, that sequences [2,3,2,1,1][2, 3, 2, 1, 1] and [3,2,1,1,2][3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.

In the second example, the discomfort of the circle is equal to 2020, since the absolute difference of 1010 and 3030 is equal to 2020.

在第一个例子中,该环的不适度等于 11,因为对应的绝对差值分别为 11、11、11 和 00。注意,序列 [2,3,2,1,1][2, 3, 2, 1, 1] 与 [3,2,1,1,2][3, 2, 1, 1, 2] 构成相同的环,仅起始点的选择不同。

在第二个例子中,该环的不适度等于 2020,因为 1010 与 3030 的绝对差值为 2020。

输入解题思路,AI测评打分。不知道怎么写?

首页