#include <iostream>
#include <algorithm>
using namespace std;
long w[1000010];
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
long n;
cin>>n;
for (int i=0;i<n;i++)cin>>w[i];
sort(w,w+n);
long tmp=w[n-2];
w[n-2]=w[0],w[0]=tmp;
for (int i=0;i<n;i++)cout<<w[i]<<' ';
cout<<endl;
sort(w,w+n,cmp);
tmp=w[n-2];
w[n-2]=w[0],w[0]=tmp;
for (int i=0;i<n;i++)cout<<w[i]<<' ';
return 0;
}
个人思路就是把最大次大放在头尾,最小时相反