Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define int long long
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n, m;
- cin >> n;
- vector<int> v(n);
- for (int i = 0; i < n; i++) {
- cin >> v[i];
- }
- cin >> m;
- vector<int> d(m);
- for (int i = 0; i < m; i++) {
- cin >> d[i];
- }
- sort(v.begin(), v.end());
- sort(d.begin(), d.end());
- int l = 0, r = 0, ans = 0;
- while(l < n && r < m) {
- while(abs(v[l] - d[r]) <= 1 && l < n && r < m){
- ++ans;
- ++l;
- ++r;
- }
- if(l <= r){
- l++;
- }else{
- r++;
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement