fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void fileIO() {
  6. #ifndef ONLINE_JUDGE
  7. freopen("input.txt", "r", stdin);
  8. freopen("output.txt", "w", stdout);
  9. #endif
  10.  
  11. #ifdef ONLINE_JUDGE
  12.  
  13. #endif
  14. }
  15.  
  16. int TC;
  17.  
  18. void get_shit_done() {
  19. int n;
  20. cin >> n;
  21.  
  22. deque<int> dq;
  23. for (int i = 0, x; i < n; ++i) {
  24. cin >> x;
  25. if (dq.empty()) {
  26. dq.push_back(x);
  27. } else if (x < dq.front()) {
  28. dq.push_front(x);
  29. } else {
  30. dq.push_back(x);
  31. }
  32. }
  33.  
  34. for (int i = 0; i < n; ++i) {
  35. cout << dq[i] << ' ';
  36. }
  37. cout << '\n';
  38. }
  39.  
  40. signed main() {
  41. fileIO();
  42. cin.tie(nullptr);
  43. cout.tie(nullptr);
  44. ios::sync_with_stdio(false);
  45.  
  46. int T = 1;
  47. cin >> T;
  48. for (TC = 1; TC <= T; ++TC) {
  49. get_shit_done();
  50. }
  51.  
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout