Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- int main() {
- int n, m;
- cin >> n >> m;
- vector<int> a(n);
- for (auto& e : a) cin >> e;
- vector<int> b(m);
- for (auto& e : b) cin >> e;
- int x = 0; ///индекс первого невзятого из a
- int y = 0; ///индекс первого невзятого из b
- vector<int> c;
- while ((x < n) && (y < m)) {
- if (a[x] < b[y]) {
- c.push_back(a[x]);
- x++;
- } else {
- c.push_back(b[y]);
- y++;
- }
- }
- while (x < n) {
- c.push_back(a[x]);
- x++;
- }
- while (y < m) {
- c.push_back(b[y]);
- y++;
- }
- for (auto e : c) cout << e << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement