Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int n, m;
- cin >> n >> m;
- vector<int> a(n), b(m);
- for (int &i : a)
- cin >> i;
- for (int &i : b)
- cin >> i;
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- int ind_a = 0, ind_b = 0;
- vector<int> ans;
- while (ind_a < n && ind_b < m)
- {
- if (a[ind_a] == b[ind_b])
- {
- if (ans.empty() || ans.back() != a[ind_a])
- ans.push_back(a[ind_a]);
- ind_b += 1;
- ind_a += 1;
- }
- else if (a[ind_a] < b[ind_b])
- ind_a += 1;
- else
- ind_b += 1;
- }
- for (int i : ans)
- cout << i << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement