# Feedback for CONCUSSIVE problem

Problem Link: CONCUSSIVE Problem - CodeChef

### Feedback

im getting right answer for the predefined testcase…and it also executing…but as soon as I press submit button…it says wrong answer…for default testcase …why?

Heres my code…i don’t know if the logic is correct…but at least it should work for default test case

include
include <bits/stdc++.h>

using namespace std;

void solve() {

int n;
cin>>n;

vector<int> nums(n);
for(int i = 0;i<n;i++) {
cin>>nums[i];
}

sort(nums.begin(),nums.end());

vector<int> concussive(n);

int i = 0; // for concussive
int j = 0; // for nums
int k = n-1; // for nums;

if(nums[0] == nums[n-1]) {
cout<<"-1"<<endl;
}else{
while(j <= k) {
concussive[i] = nums[j];
i++;
concussive[i] = nums[k];
i++;
j++;
k--;
}

for(int i = 0;i<n;i++) {
cout<<concussive[i]<<" ";
}
cout<<endl;
}

}

int main() {

int t;
cin>>t;

while(t--) {
solve();
}
return 0;

}

@amman27
Plzz refer my code for better understanding of the logic.

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<algorithm>
#include<numeric>

using namespace std;
typedef long long int lli;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//typedef long long int lli;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> multi_pbds;
//typedef tree<pair<int , int>, null_type, less<pair<int ,int>>, rb_tree_tag, tree_order_statistics_node_update> pbdsp;
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define nl "\n";
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define db long double
#define prq priority_queue<lli>
#define psq priority_queue<lli,vector<lli>,greater<lli>>
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define vlli vector<lli>
#define mslli multiset<lli>
#define inf 1e17
#define sp " "
#define pb push_back
#define pie 3.14159265358979323846
#define test lli t; cin>>t; while(t--)

int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
test{
lli n,ch=0;
cin>>n;
lli a[n];
for(lli i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
lli b[n];
lli j=0;
for(int i=0;i<n;i+=2)
{
b[i]=a[j];
j++;
}
for(int i=1;i<n;i+=2)
{
b[i]=a[j];
j++;
}
for(int i=1;i<n-1;i++)
{
if(b[i]>b[i-1]&&b[i]>b[i+1])
{
continue;
}
else if(b[i]<b[i-1]&&b[i]<b[i+1])
continue;
else
{
ch=1;
}
}
if(ch)
{
j=0;
for(int i=1;i<n;i+=2)
{
b[i]=a[j];
j++;
}
for(int i=0;i<n;i+=2)
{
b[i]=a[j];
j++;
}
for(int i=1;i<n-1;i++)
{
if(b[i]>b[i-1]&&b[i]>b[i+1])
{
continue;
}
else if(b[i]<b[i-1]&&b[i]<b[i+1])
continue;
else
{
ch=2;
}
}
if(ch==1)
{
for(int i=0;i<n;i++)
{
cout<<b[i]<<" ";
}
}
else
cout<<-1;
}
else
{
for(int i=0;i<n;i++)
{
cout<<b[i]<<" ";
}
}
cout<<endl;
}

}