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. GIS科研站

    http://www.3sbase.com/3sbase/ 近年来,地理信息科学发展迅猛,科研人员日益增多,但目前尚缺乏良好的交流平台,致使优秀的科研成果难以推广.同时,对于大量的GIS学生而言,对国 ...

  2. itoa : Convert integer to string

      Quote from:  http://www.cplusplus.com/reference/cstdlib/itoa/   function   Required header : <s ...

  3. [翻译][MVC 5 + EF 6] 3:排序、过滤、分页

    原文:Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application 1.添加排序: 1. ...

  4. Java基础巩固----泛型

    注:参考书籍:Java语言程序设计.本篇文章为读书笔记,供大家参考学习使用 1.使用泛型的主要优点是能够在编译时而不是在运行时检查出错误,提高了代码的安全性和可读性,同时也提高了代码的复用性. 1.1 ...

  5. python相关博客

    入门:http://www.pythontip.com/ Python之禅--大道至简 美胜于丑,显胜于隐,简胜于繁,繁胜于杂,平胜于迭,疏胜于密,读胜于写...名可名, 请常名 http://www ...

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

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

  7. [C#]async/Await 使用小计

    如果指定使用 异步 或 异步 修饰符,方法是异步方法,可以实现以下两个函数.  • 清单异步方法可以使用 Await 或指定的 等待 悬挂点.  等待运算符通知编译器异步方法不能继续点的过去,直到等待 ...

  8. [C#]『PLINQ』任务并行库使用小计

    并行 LINQ (PLINQ) 是 LINQ to Objects 的并行实现. PLINQ 实现完整的 LINQ 标准查询运算符集作为 T:System.Linq 命名空间的扩展方法,并具有用于并行 ...

  9. 不能正确获得上次构建以来的Commit

    不能正确获得上次构建以来的Commit 如何解决?

  10. js 遍历json对象

    //方法一: var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13} ...