fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 100000;
  5.  
  6. int main() {
  7. int n, m, v[ MAX_SIZE + 1], w[ MAX_SIZE + 1];
  8. cin >>n ;
  9. int isHigh = 1;
  10. for(int i = 1; i <= n; ++i){
  11. cin >> v[i] ;
  12. }
  13. cin >>m;
  14. for(int j = 1; j <= m; ++j) {
  15. cin >> w[j];
  16. }
  17. int j = 1;
  18. for(int i = 1; i <= n;) {
  19. if (v[i] > w[j]) {
  20. isHigh = 0;
  21. }
  22. if (isHigh == 0) {
  23. cout << w[j++] << " ";
  24. } else {
  25. cout << v[i++] <<" ";
  26. }
  27. //-456 -359 -321 -201 -108 -94 52 7895
  28. //-1 0 125 325 6581
  29.  
  30. isHigh = 1;
  31. if (i > n && j <= m) {
  32. for (;v[i] <= w[j] && j <= m || v[i] >= w[j] && j <= m ;) {
  33. cout << w[j++] << " ";
  34. }
  35. }
  36. if (j > m && i <= n) {
  37. for (;v[i] > w[j] ;) {
  38. cout << v[i++] <<" ";
  39. }
  40. }
  41. }
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5532KB
stdin
3
-126 -19 100
6
-2 0 2 5 89 91
stdout
-126 -19 -2 0 2 5 89 91 100