fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define int long long
  4. #define f first
  5. #define s second
  6. #define file(a) freopen(a".inp","r",stdin);freopen(a".out","w",stdout);
  7. #define fastoi ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  8. #define TIME cerr << "\n\n" << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
  9. #define ii pair<ll,ll>
  10. using namespace std;
  11. const int maxn = 1e6+5;
  12. const int MOD = 1e9+7;
  13. ll n,k,a[maxn],pre[maxn],ans=0,cnt=0,b[maxn];
  14. int32_t main()
  15. {
  16. fastoi;
  17. #ifndef ONLINE_JUDGE
  18. file("test");
  19. #endif
  20.  
  21. cin >> n;
  22. for (int i=1;i<=n;i++) cin >> a[i];
  23. for (int i=1;i<=n;i++) cin >> b[i];
  24.  
  25. ll l=1,r=1;
  26. while (l<=n && r<=n)
  27. {
  28. if (a[l] == b[r])
  29. {
  30. cout << a[l] << ' ' << b[r] << ' ';
  31. l++;
  32. r++;
  33. }
  34. else if (a[l] < b[r])
  35. {
  36. cout << a[l] << ' ';
  37. l++;
  38. }
  39. else
  40. {
  41. cout << b[r] << ' ';
  42. r++;
  43. }
  44. }
  45.  
  46. /// kiểm tra xem đã xuất hết số ra chưa
  47.  
  48. while (l<=n)
  49. {
  50. cout << a[l] << ' ';
  51. l++;
  52. }
  53. while (r<=n)
  54. {
  55. cout << b[r] << ' ';
  56. r++;
  57. }
  58. TIME;
  59. return 0;
  60. }
  61. //─────────────────────────────────────────────────────────
  62. //─██████──██████─██████████─██████████████─██████──██████─
  63. //─██░░██──██░░██─██░░░░░░██─██░░░░░░░░░░██─██░░██──██░░██─
  64. //─██░░██──██░░██─████░░████─██░░██████████─██░░██──██░░██─
  65. //─██░░██──██░░██───██░░██───██░░██─────────██░░██──██░░██─
  66. //─██░░██████░░██───██░░██───██░░██████████─██░░██──██░░██─
  67. //─██░░░░░░░░░░██───██░░██───██░░░░░░░░░░██─██░░██──██░░██─
  68. //─██░░██████░░██───██░░██───██░░██████████─██░░██──██░░██─
  69. //─██░░██──██░░██───██░░██───██░░██─────────██░░██──██░░██─
  70. //─██░░██──██░░██─████░░████─██░░██████████─██░░██████░░██─
  71. //─██░░██──██░░██─██░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─
  72. //─██████──██████─██████████─██████████████─██████████████─
  73. //─────────────────────────────────────────────────────────
Success #stdin #stdout #stderr 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr

6.482 ms