Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- void solve() {
- int i, j, n, k;
- cin >> n;
- int a[n];
- int prev;
- cin >> prev;
- a[0] = prev;
- int rep = 1;
- bool nope = false;
- for (i = 1; i < n; ++i) {
- cin >> a[i];
- if (a[i] == prev) {
- rep++;
- } else {
- prev = a[i];
- rep = 1;
- }
- if (rep > 2) {
- nope = true;
- }
- }
- if (nope || rep > 1) {
- cout << "NO\n";
- return;
- }
- sort(a, a + n);
- cout << "YES\n";
- // this part is probably the one that is failing
- for (i = 0; i < n; i += 2) cout << a[i] << " ";
- for (i = n - 1 - (n & 1); i >= 0; i -= 2) cout << a[i] << " ";
- cout << endl;
- }
- int32_t main() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios::sync_with_stdio(0);
- cout.tie(0);
- cin.tie(0);
- int _t = 1;
- cin >> _t;
- while (_t--)
- solve();
- }
Add Comment
Please, Sign In to add comment