fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. unordered_map<int, int> mp;
  5. priority_queue<int> le;
  6. priority_queue<int, vector<int>,
  7. greater<int>> chan;
  8.  
  9. int main()
  10. {
  11. int n;
  12. cin >> n;
  13. for(int i = 1; i <= n; i++)
  14. {
  15. int c;
  16. cin >> c;
  17. if(c == 0)
  18. mp[i] = -1;
  19. else if(c % 2)
  20. mp[i] = 1, le.push(c);
  21. else
  22. chan.push(c);
  23. }
  24. for(int i = 1; i <= n; i++)
  25. {
  26. if(mp[i] == -1)
  27. cout << 0 << ' ';
  28. else if(mp[i])
  29. {
  30. cout << le.top() << ' ';
  31. le.pop();
  32. }
  33. else
  34. {
  35. cout << chan.top() << ' ';
  36. chan.pop();
  37. }
  38. }
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty