fork download
  1. #include<bits/stdc++.h>
  2. #define MOD 1000000007
  3. #define ll long long
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. std::ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. int t;
  11. cin >> t;
  12. while (t--)
  13. {
  14. int n;
  15. cin >> n;
  16. int a[n];
  17. for (int i=0; i<n; ++i) cin >> a[i];
  18. sort(a, a+n);
  19. int b[n], pos=0;
  20. for (int i=0; i<n; i+=2) b[i]=a[pos++];
  21. for (int i=1; i<n; i+=2) b[i]=a[pos++];
  22. for (int i=0; i<n; ++i) cout << b[i] << " ";
  23. cout << "\n";
  24. }
  25. }
Success #stdin #stdout 0.01s 5284KB
stdin
2
4
1 2 2 1
3
1 3 2
stdout
1 2 1 2 
1 3 2