CF 1131C Birthday

C. Birthday
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.web

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.ide

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

Input

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

The second line contains integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109) denoting heights of every child.code

Output

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.orm

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

Examples
input
Copy
5
2 1 1 3 2
output
Copy
1 2 3 2 1
input
Copy
3
30 10 20
output
Copy
10 20 30
Note

In the first example, the discomfort of the circle is equal to 11, since the corresponding absolute differences are 111111 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.ip

【題意】

n我的圍成一個圈,每一個人有本身一個高度,讓你對這n我的進行從新的排列,使得知足任意兩我的之間高度差的最大值最小。ci

 

【分析】

咱們就能夠很容易的得出規律來,對高度序列排序以後n開始先輸出下標序列爲偶數的,而後在從1開始輸出下標序列爲奇數的值。

 

【代碼】

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=105;
int n,a[N];
inline void Init(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
}
inline void Solve(){
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i+=2) printf("%d ",a[i]);
	for(int i=n&1?n-1:n;i;i-=2) printf("%d%s",a[i],i<2?"":" ");
}
int main(){
	Init();
	Solve();
	return 0;
}
相關文章
相關標籤/搜索