Mahmoud_Hawara

Untitled

Jul 5th, 2022
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #pragma GCC optimize("-Ofast")
  4. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
  5. #pragma GCC optimize("-ffast-math")
  6. #pragma GCC optimize("-funroll-loops")
  7. #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
  8. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  9. const long long MOD = 1e9 + 7, OO = 1e18;
  10. const double PI = acos(-1);
  11. const int N = 1e5 + 5;
  12. const int dx[4] = {0, 0, 1, -1};
  13. const int dy[4] = {1, -1, 0, 0};
  14.  
  15. long long n, x, freq[5005], cnt, ans[N], pointer = 1, mx = -OO;
  16.  
  17. int main()
  18. {
  19.     IO  
  20.     cin >> n;
  21.     for (int i = 1; i <= n; i++)
  22.     {
  23.         cin >> x;
  24.         freq[x]++;
  25.         mx = max(mx, x);
  26.     }
  27.     for (int i = 1; i <= mx; i++)
  28.     {
  29.         if (freq[i])
  30.         {
  31.             freq[i]--;
  32.             ans[pointer++] = i;
  33.             cnt++;
  34.         }
  35.     }
  36.     for (int i = mx - 1; i >= 1; i--)
  37.     {
  38.         if (freq[i])
  39.         {
  40.             freq[i]--;
  41.             ans[pointer++] = i;
  42.             cnt++;
  43.         }
  44.     }
  45.     cout << cnt << '\n';
  46.     for (int i = 1; i <= cnt; i++)cout << ans[i] << ' ';
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment