fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
  7. #define MULTIPLE_TEST int t;cin>>t;while(t--)
  8. #define pi (2*acos(0.0))
  9.  
  10. //local array size = 1e5, global = 1e8
  11. //int = 1e9, long long = 1e18
  12. // 1 sec = 1e7 ~ 1e8
  13.  
  14. const int N = 1e7+10;
  15.  
  16. void merge(int a1[], int a2[], int n, int m){
  17. int i=0,j=0;
  18.  
  19. while(i<=n){
  20. if(a1[i]>a2[0]){
  21. swap(a1[i],a2[0]);
  22. int temp = a2[0];
  23.  
  24. int k;
  25. for (k = j+1; k < m && a2[k]<temp; k++)
  26. {
  27. a2[k-1]=a2[k];
  28. }
  29. a2[k-1]=temp;
  30. }
  31. i++;
  32.  
  33. }
  34. }
  35.  
  36. int main(){
  37.  
  38. fastio
  39.  
  40. int n,m; cin>>n>>m;
  41. int a1[n],a2[m];
  42. for (int i = 0; i < n; i++)
  43. {
  44. cin>>a1[i];
  45. }
  46. for (int i = 0; i < m; i++)
  47. {
  48. cin>>a2[i];
  49. }
  50. merge(a1,a2,n,m);
  51. for (int i = 0; i < n; i++)
  52. {
  53. cout<<a1[i]<<" ";
  54. }cout<<'\n';
  55. for (int i = 0; i < m; i++)
  56. {
  57. cout<<a2[i]<<" ";
  58. }cout<<'\n';
  59.  
  60.  
  61.  
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5504KB
stdin
4 5
1 3 5 7
0 2 6 8 9
stdout
0 1 2 3 
5 6 7 8 9