fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <functional>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int input()
  9. {
  10. int x;
  11. cin >> x;
  12. return x;
  13. }
  14.  
  15. int main()
  16. {
  17. vector<int> v(input());
  18. generate(v.begin(), v.end(), input);
  19. while (v.size() != 0) {
  20. make_heap(v.begin(), v.end(), greater<int>());
  21. cout << v.front() << endl;
  22. *v.begin() = v.back();
  23. v.pop_back();
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 15240KB
stdin
6
1 6 4 3 5 2
stdout
1
2
3
4
5
6