# Feedback for CONCUSSIVE problem

Problem Link: CONCUSSIVE Problem - CodeChef

### Feedback

My code is giving right output for test case 0 during run but failing even test 0 on submit . How could this even happen .

Here’s the code :

#include<bits/stdc++.h>
include <ext/pb_ds/assoc_container.hpp>
include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less, rb_tree_tag, tree_order_statistics_node_update> pbds;

//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

//=======================================================================
define int long long
define vi vector
define vvi vector<vector>
define pii pair<int,int>
define vpi vector<pair<int,int>>
define all(x) (x).begin(),(x).end()
define countbits(x) __builtin_popcount(x)
define vpi vector<pair<int,int>>
define yes cout<<“YES”<<endl
define no cout<<“NO”<<endl
define pb push_back
define ff first
define ss second

int mod = 1e9+7;

int max(int a,int b){return a>b ? a : b ;}

int min(int a,int b){return a<b ? a : b ;}

int hcf(int a,int b){
return (b==0 ? a : hcf(b,a%b));
}

int lcm(int x,int y){
return (x*y)/hcf(x,y);
}

void printarray(vector &a){
for(int i=0 ; i<a.size() ; i++){
cout<<a[i]<<" ";
}
cout<<endl;
}

bool valid(vi &a){
for(int i=1 ; i<a.size()-1 ; i++){
if(((a[i]>a[i-1]) && (a[i]>a[i+1])) || ((a[i]<a[i-1]) && (a[i]<a[i+1]))){
continue;
}
else{
return false;
}
}
return true;
}

void solve(){
int n;
cin>>n;
vector a(n,0);
for(int i=0 ; i<n ; i++){
cin>>a[i];
}
vi ans1(n,0);
sort(all(a));
int id=0;
for(int i=0 ; i<n ; i++){
if(id>=n){
id=1;
}
ans1[id]=a[i];
id+=2;
}
if(valid(ans1)){
printarray(ans1);
return;
}
reverse(all(a));
vi ans2(n,0);
id=0;
for(int i=0 ; i<n ; i++){
if(id>=n){
id=1;
}
ans2[id]=a[i];
id+=2;
}
if(valid(ans2)){
printarray(ans2);
return;
}
cout<<-1<<endl;
return;
}

int32_t main(){
int t;
cin>>t;
while(t–){
solve();
}

``````return 0;
``````

}