CF347A.Difference Row

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You want to arrange nn integers a1,a2,...,ana_{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 x1,x2,...,xnx_{1},x_{2},...,x_{n} , where sequence xx is a permutation of sequence aa . The value of such an arrangement is (x1x2)+(x2x3)+...+(xn1xn)(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 xx that corresponds to an arrangement of the largest possible value.

输入格式

The first line of the input contains integer nn ( 2<=n<=1002<=n<=100 ). The second line contains nn space-separated integers a1a_{1} , a2a_{2} , ...... , ana_{n} ( ai<=1000|a_{i}|<=1000 ).

输出格式

Print the required sequence x1,x2,...,xnx_{1},x_{2},...,x_{n} . Sequence xx should be the lexicographically smallest permutation of aa that corresponds to an arrangement of the largest possible value.

输入输出样例

  • 输入#1

    5
    100 -100 50 0 -50
    

    输出#1

    100 -50 0 50 -100 
    

说明/提示

In the sample test case, the value of the output arrangement is (100(50))+((50)0)+(050)+(50(100))=200(100-(-50))+((-50)-0)+(0-50)+(50-(-100))=200 . No other arrangement has a larger value, and among all arrangements with the value of 200200 , the output arrangement is the lexicographically smallest one.

Sequence x1,x2,... ,xpx_{1},x_{2},...\ ,x_{p} is lexicographically smaller than sequence y1,y2,... ,ypy_{1},y_{2},...\ ,y_{p} if there exists an integer rr (0<=r<p) such that x1=y1,x2=y2,... ,xr=yrx_{1}=y_{1},x_{2}=y_{2},...\ ,x_{r}=y_{r} and x_{r+1}<y_{r+1} .

首页