Guest User

INCRDECR

a guest
Jun 27th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4.  
  5.  
  6. void solve() {
  7.     int i, j, n, k;
  8.     cin >> n;
  9.     int a[n];
  10.     int prev;
  11.     cin >> prev;
  12.     a[0] = prev;
  13.     int rep = 1;
  14.     bool nope = false;
  15.     for (i = 1; i < n; ++i) {
  16.         cin >> a[i];
  17.         if (a[i] == prev) {
  18.             rep++;
  19.         } else {
  20.             prev = a[i];
  21.             rep = 1;
  22.         }
  23.         if (rep > 2) {
  24.             nope = true;
  25.         }
  26.     }
  27.     if (nope || rep > 1) {
  28.         cout << "NO\n";
  29.         return;
  30.     }
  31.     sort(a, a + n);
  32.     cout << "YES\n";
  33.  
  34.     // this part is probably the one that is failing
  35.     for (i = 0; i < n; i += 2) cout << a[i] << " ";
  36.     for (i = n - 1 - (n & 1); i >= 0; i -= 2) cout << a[i] << " ";
  37.     cout << endl;
  38. }
  39.  
  40. int32_t main() {
  41. #ifndef ONLINE_JUDGE
  42.     freopen("input.txt", "r", stdin);
  43.     freopen("output.txt", "w", stdout);
  44. #endif
  45.     ios::sync_with_stdio(0);
  46.     cout.tie(0);
  47.     cin.tie(0);
  48.     int _t = 1;
  49.     cin >> _t;
  50.     while (_t--)
  51.         solve();
  52. }
Add Comment
Please, Sign In to add comment