fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24.  
  25. vector<int> a;
  26. vector<int> b;
  27.  
  28. void consistency(int n, int m) {
  29.  
  30. int i = n-1;
  31. int j = 0;
  32.  
  33. while(i>=0 && j<m){
  34. if(a[i] > b[j]){
  35. swap(a[i], b[j]);
  36. }
  37. else break;
  38. i--;
  39. j++;
  40. }
  41.  
  42. sort(begin(a), end(a));
  43. sort(begin(b), end(b));
  44.  
  45. for(int i=0; i<n; i++) cout << a[i] << " ";
  46. for(int j=0; j<m; j++) cout << b[j] << " ";
  47. cout << endl;
  48.  
  49.  
  50. }
  51.  
  52.  
  53. void solve() {
  54.  
  55. int n, m;
  56. cin >> n >> m ;
  57. a.resize(n);
  58. b.resize(m);
  59. for(int i=0; i<n; i++) cin >> a[i];
  60. for(int i=0; i<m; i++) cin >> b[i];
  61.  
  62. consistency(n, m);
  63.  
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. int32_t main() {
  71. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  72.  
  73. int t = 1;
  74. // cin >> t;
  75. while (t--) {
  76. solve();
  77. }
  78.  
  79. return 0;
  80. }
Success #stdin #stdout 0s 5316KB
stdin
4 3
2 3 9 11
1 7 8
stdout
1 2 3 7 8 9 11