A12401 | Birthday
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Cowboy Vlad has a birthday today! There are $n$ 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 $1$ to $n$ in a circle order, that is, for every $i$ child with number $i$ will stand next to the child with number $i+1$ , also the child with number $1$ stands next to the child with number $n$ . 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.
Formally, let's number children from $1$ to $n$ in a circle order, that is, for every $i$ child with number $i$ will stand next to the child with number $i+1$ , also the child with number $1$ stands next to the child with number $n$ . 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.
输入格式
The first line contains a single integer $n$ ( $2 \leq n \leq 100$ ) — the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ) denoting heights of every child.
The second line contains integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ) denoting heights of every child.
输出格式
Print exactly $n$ 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.
If there are multiple possible answers, print any of them.
输入输出样例
输入 #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 $1$ , since the corresponding absolute differences are $1$ , $1$ , $1$ and $0$ . Note, that sequences $[2, 3, 2, 1, 1]$ and $[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 $20$ , since the absolute difference of $10$ and $30$ is equal to $20$ .
In the second example, the discomfort of the circle is equal to $20$ , since the absolute difference of $10$ and $30$ is equal to $20$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted