Codeforces Round #541 (Div. 2) C. Birthday

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.

Input

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

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

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.

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

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

有n个人围成一个圈,每个人有自己一个高度,让你对这n个人进行重新的排列,使得满足任意两个人之间高度差的最大值最小

题目要求两个人之间的高度差尽可能的小,那么就要把数据差小的尽可能的安排到一起,自然就想到了首先要进行一个排序

 首先排序,第一次尝试从小到大输出(不输出重复的数字)之后把剩下的从大到小输出,然后就错了……懵比!第四个样例就错了。

第二次就是中间数字最大,然后依次左右放置,也就是先输出排序后的数组下标为奇数数字,之后反向输出下标为偶数的数字

#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<iostream>
#include<iomanip>
#define mset(a,b)   memset(a,b,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
//const ll mod=1e9+7;
const int N=30000;
const int inf=0x3f3f3f3f;
//priority_queue<int,vector<int>,greater<int> >q;
int n,a,b,x,y,sum;
int s1[105];
int s2[105];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&s1[i]);
    }
    memset(s2,0,sizeof(s2));
    sort(s1+1,s1+n+1);
    for(int i=1;i<=n;i++)
    {
        if(i%2==1)
        {
            printf("%d ",s1[i]);
            s2[i]=1;
        }
    }
    for(int i=n;i>=1;i--)
    {
        if(!s2[i])
            printf("%d ",s1[i]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Kuguotao/article/details/88227949