-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergingArrays.cpp
49 lines (41 loc) · 1.25 KB
/
mergingArrays.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
template<typename T1, typename T2> // cin >> pair<T1, T2>
istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); }
template<typename T> // cin >> vector<T>
istream& operator>>(istream &istream, vector<T> &v) {for (auto &it : v)cin >> it; return istream;}
template<typename T1, typename T2> // cout << pair<T1, T2>
ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); }
template<typename T> // cout << vector<T>
ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; }
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
#define all(x) x.begin(), x.end()
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
cin >> a >> b;
vector<int> c(n + m);
int i = 0, j = 0, k = 0;
while (i < n || j < m) {
if (j == b.size() || (i < a.size() && a[i] < b[j])) {
c[k] = a[i];
i++, k++;
} else {
c[k] = b[j];
j++, k++;
}
}
cout << c << endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cout.tie(0);
solve();
return 0;
}