Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///https://codeforces.com/problemset/problem/489/B
- #include<iostream>
- #include<vector>
- #include<algorithm>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<int> a(n);
- for (auto& e : a) cin >> e;
- sort(a.begin(), a.end());
- int m;
- cin >> m;
- vector<int> b(m);
- for (auto& e : b) cin >> e;
- sort(b.begin(), b.end());
- vector<bool> is_taken(m, false);
- int answ = 0;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (!is_taken[j] && (abs(a[i] - b[j]) <= 1)) {
- answ++;
- is_taken[j] = true;
- break;
- }
- }
- }
- cout << answ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement