fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define yes cout<<"YES\n";
  6. #define no cout<<"NO\n";
  7. const int N=3e5+7;
  8. ll T = 1, a[N], b[N];
  9. void solve()
  10. {
  11. int n, m;
  12.  
  13. cin >> n >> m;
  14.  
  15. for(int i = 1; i <= n; i++)
  16. cin >> a[i];
  17.  
  18. for(int i = 1; i <= m; i++)
  19. cin >> b[i];
  20.  
  21. int l = 1, r = 1;
  22.  
  23. while(l <= n && r <= m){
  24. if(a[l] <= b[r])
  25. cout << a[l] << ' ', l++;
  26. else
  27. cout << b[r] << ' ', r++;
  28. }
  29.  
  30. while(l <= n)
  31. cout << a[l] << ' ', l++;
  32.  
  33. while(r <= m)
  34. cout << b[r] << ' ', r++;
  35. }
  36. int main()
  37. {
  38. ios::sync_with_stdio(NULL);
  39. cin.tie(0);
  40. cout.tie(0);
  41.  
  42. // freopen("","r", stdin);
  43. // freopen("","w", stdout);
  44. // cin>>T;
  45. while(T--)
  46. solve();
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 5716KB
stdin
6 7
1 6 9 13 18 18
2 3 8 13 15 21 25
stdout
1 2 3 6 8 9 13 13 15 18 18 21 25