301835: CF347A. Difference Row
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Difference Row
题意翻译
一串数列的价值是这样计算的: (x[1]-x[2])+(x[2]-x[3])+···+(x[n-1]-x[n]) 这串数列的顺序是可以改变的,试求出价值最大的一种排列(若有多种答案,按字典序最小的一种输出)。题目描述
You want to arrange $ n $ integers $ a_{1},a_{2},...,a_{n} $ 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 $ x_{1},x_{2},...,x_{n} $ , where sequence $ x $ is a permutation of sequence $ a $ . The value of such an arrangement is $ (x_{1}-x_{2})+(x_{2}-x_{3})+...+(x_{n-1}-x_{n}) $ . 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.输入输出格式
输入格式
The first line of the input contains integer $ n $ ( $ 2<=n<=100 $ ). The second line contains $ n $ space-separated integers $ a_{1} $ , $ a_{2} $ , $ ... $ , $ a_{n} $ ( $ |a_{i}|<=1000 $ ).
输出格式
Print the required sequence $ x_{1},x_{2},...,x_{n} $ . Sequence $ x $ should be the lexicographically smallest permutation of $ a $ that corresponds to an arrangement of the largest possible value.
输入输出样例
输入样例 #1
5
100 -100 50 0 -50
输出样例 #1
100 -50 0 50 -100