Quick actions

cmd+k|ctrl+k

Navigation

Languages

CF_726_C

Snippet info

Language

Cpp

Visibility

public

Author

karthik.pasupulatei

Created

2021-06-21T05:50:10.891373Z

Updated

2021-06-21T05:50:10.891373Z

// Problem: C. Challenging Cliffs
// Contest: Codeforces - Codeforces Round #726 (Div. 2)
// URL: https://codeforces.com/contest/1537/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include "bits/stdc++.h"
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;


int main(){
    FIO
    ll t ; cin >> t ; 
    while(t--){
    	ll n ; cin>> n ; 
    	vector<ll> v(n  , 0 ) ; 
    	for(auto &c : v)cin>> c; 
    	sort(v.begin() , v.end()) ;
    	ll Min = INT_MAX  , idx  = -1 ;  
    	for(int i = 1 ; i < n ;i++){
    		if(Min > (v[i]-v[i-1])){
    			Min  = (v[i]-v[i-1]) ; 
    			idx  =  i ; 
    		} 
    	}
    	cout<< v[idx-1] <<" " ; 
    	for(int i = idx+1  ; i < n ;i++ ){
    		cout << v[i] << " " ; 
    	}
    	for(int i = idx-2 ; i >= 0 ; i--){
    		cout << v[i] <<" " ; 
    	}
    	cout<<v[idx] << "\n" ; 
    } 
    return 0 ; 
}
INFO