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.

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个人进行重新的排列,使得满足任意两个人之间高度差的最大值最小。

【分析】

我们就可以很容易的得出规律来,对高度序列排序之后,从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;
}

 

 

 

CF 1131C Birthday的更多相关文章

  1. CF 1131A,1131B,1131C,1131D,1131F(Round541 A,B,C,D,F)题解

    A. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  3. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  4. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  5. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  6. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  7. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  8. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  9. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

随机推荐

  1. JS的document.all函数使用示例

    JS的document.all函数虽然被document.getElement......代替,但是在使用中还是较为常见,下面为大家详细介绍下具体的使用示例: 一: document.all是页面内所 ...

  2. 编写CentOS的System V init启动脚本

    系统本身自带了说明,在/usr/share/doc/initscripts-(*)/sysvinitfiles,内容如下: 所有System V init脚本都命名为/etc/rc.d/init.d/ ...

  3. pygame 笔记-3 角色动画及背景的使用

    上二节,已经知道如何控制基本的运动了,但是只有一个很单调的方块,不太美观,本节学习如何加载背景图,以及角色的动画. 素材准备:(原自github) 角色动画的原理:动画都是一帧帧渲染的,比如向左走的动 ...

  4. MiniUI破解方法

    解决JQuery MiniUI前端库到期alert弹窗 MINIUI的到期提示是通过JS的Alert 方法弹出的. 那么我们可以不可以截获所有Alert方法,过滤文本.然后….你们懂得 我们只需要在页 ...

  5. socket.io常用api

    1. 服务端 io.on('connection',function(socket)); 监听客户端连接,回调函数会传递本次连接的socket io.sockets.emit('String',dat ...

  6. Css3实现波浪线效果1

    一.波浪线 ,常用 .info::before { content: ''; position: absolute; top: 30px; width: 100%; height: 0.25em; b ...

  7. ionic ion-tab图标修改, 自定义tab图标

    遇到需要自定义tab图标很简单, 只需要自定义相应的css就可以了, 这里要注意的是如何调整背景图片的大小. <ion-view hide-back-button="false&quo ...

  8. N-gram的简单的介绍

    目录: 1. 联合概率 2. 条件概率 3. N-gram的计算方式 4. 评估N-gram的模型. 前言: N-gram是机器学习中NLP处理中的一个较为重要的语言模型,常用来做句子相似度比较,模糊 ...

  9. elasticsearch外网访问设置

    默认情况下安装elasticsearch之后是无法进行外网访问的,可以通过设置来完成这一目的 1.更改配置文件 [***@elk01 ~]$ vim elk/config/elasticsearch. ...

  10. Effective Java 第三版——77. 不要忽略异常

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...