A. Difference Row
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You want to arrange n integers a1, a2, ..., an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.

More formally, let's denote some arrangement as a sequence of integers x1, x2, ..., xn, where sequence x is a permutation of sequence a. The value of such an arrangement is (x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).

Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence x that corresponds to an arrangement of the largest possible value.

Input

The first line of the input contains integer n (2 ≤ n ≤ 100). The second line contains n space-separated integers a1, a2, ..., an (|ai| ≤ 1000).

Output

Print the required sequence x1, x2, ..., xn. Sequence x should be the lexicographically smallest permutation of a that corresponds to an arrangement of the largest possible value.

Sample test(s)
input
5
100 -100 50 0 -50
output
100 -50 0 50 -100 
 #include<stdio.h>
#include<stdlib.h>
int a[];
int comp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
} int main()
{
int n,i;
while(~scanf("%d",&n))
{
for(i = ;i < n;i ++)
scanf("%d",&a[i]);
qsort(a,n,sizeof(a[]),comp);
printf("%d ",a[n-]);
for(i = ;i < n-;i ++)
printf("%d ",a[i]);
printf("%d\n",a[]);
}
return ;
}

A. Difference Row的更多相关文章

  1. codeforces A. Difference Row

    link:http://codeforces.com/contest/347/problem/A 开始看起来很复杂的样子,但是刚写下样例,就发现因为中间的都消去了,其实起作用的就是最大值和最小值=_= ...

  2. codeforces A. Difference Row 解题报告

    题目链接:http://codeforces.com/problemset/problem/347/A 题目意思:给出一个序列 a1, a2, ..., an , 通过重排序列,假设变成 x1, x2 ...

  3. codeforces round #201 Div2 A. Difference Row

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  4. CodeForces 347A Difference Row (水题)

    题意:给定 n 个数,让你找出一个排列满足每个数相邻作差之和最大,并且要求字典序最小. 析:这个表达式很简单,就是把重新组合一下,就成了x1-xn,那么很简单,x1是最大的,xn是最小的,中间排序就好 ...

  5. codeforces 347A - Difference Row

    给你一个序列,让你求(x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).值最大的一个序列,我们化简一下公式就会发现(x1 - x2) + (x2 - x3) + . ...

  6. RGB 颜色空间转 HSI 颜色空间的matlab程序实现

    RGB 颜色空间转 HSI 颜色空间的matlab程序实现 2014.10.20之前的内容有误,这里依据wikipedia更新了算法内容. 算法以wiki为准 https://en.wikipedia ...

  7. OLAP vs OLTP: what makes the difference

    OLAP vs OLTP: what makes the difference OLPT and OLAP are complementingtechnologies. You can't live ...

  8. Difference between 'SAME' and 'VALID' padding

    Difference between 'SAME' and 'VALID' padding 'SAME' padding 和 'VALID' padding 的区别 If you like ascii ...

  9. iOS7 UITableView Row Height Estimation

    This post is part of a daily series of posts introducing the most exciting new parts of iOS7 for dev ...

随机推荐

  1. Objective-C 成员变量的访问修饰即成员变量可见性解析

    总体来说Objective-C的访问成员变量可见性和C++基本一样,只是多了个@package. 以下是详细说明: 例子: @interface CTPerson : NSObject { @priv ...

  2. asp:DateDiff 函数

    DateDiff 函数 返回 Variant (Long) 的值,表示两个指定日期间的时间间隔数目. 语法 DateDiff(interval, date1, date2[, firstdayofwe ...

  3. PHP学习笔记(五)

    关于Response header 的一些小知识: Host :address url,  host 是浏览器给服务器提供的address标识.由于http协议是无状态的,服务器需要根据host的这个 ...

  4. Ibatis学习记录

    几大要素:1.jdbc.properties //数据库连接配置2.SqlMapContext.xml //主配置文件3.user_SqlMap.xml //映射文件4.三层框架 创建Ibatis工程 ...

  5. mysql学习笔记(1)

    参考教材<MySQL入门经典>  王雨竹 高飞      机械工业出版社 软件下载:http://www.mysql.com 安装好后打开命令提示符 (黑窗口) net start mys ...

  6. [zz]安装Ubuntu 15.10后要做的事

    很有用,收藏 http://blog.csdn.net/skykingf/article/details/45267517

  7. python 自动化之路 day 08_2 网络编程

    本节内容 Socket介绍 Socket参数介绍 基本Socket实例 Socket实现多连接处理 通过Socket实现简单SSH 通过Socket实现文件传送 作业:开发一个支持多用户在线的FTP程 ...

  8. [Leveldb源码剖析疑问]-block_builder.cc之Add函数

    Add函数是给一个Data block中添加对应的key和value,函数源码如下,其中有一处不理解: L30~L34是更新last_key_的,不理解这里干嘛不直接last_key_ = key.T ...

  9. linux强大IDE——Geany配置说明

    今天开始用Ubuntu了(主要是为了防止自己在windows下不自觉的打游戏之类的)   刚开始用的很不习惯  找不到合适的编译器(DEV c++什么时候才能出Linux的啊)  先后下了codeli ...

  10. mac 生成支付宝的rsa公钥和私钥 php版本

    openssl genrsa -out rsa_private_key.pem 1024 公钥 openssl rsa -in rsa_private_key.pem -pubout -out rsa ...