fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n; cin >> n;
  7. unordered_map<int,int> freq;
  8. int x;
  9. bool ans = true;
  10. for(int i = 0; i < n; i++) {
  11. cin >> x;
  12. freq[x]++;
  13. if(freq[x] > ceil(n/2.0))
  14. ans = false;
  15. }
  16.  
  17. int tmp = n;
  18. cout << ((ans) ? "YES\n" : "NO\n");
  19. while(tmp) {
  20. for(auto &x : freq)
  21. if(x.second) {
  22. cout << x.second-- << " ";
  23. tmp--;
  24. }
  25. }
  26.  
  27. cout << "\n";
  28. }
  29.  
Success #stdin #stdout 0.01s 5288KB
stdin
3
1 1 2
stdout
YES
1 2 1