Advertisement
nq1s788

бал в берлгу за nm

Jul 7th, 2024
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. ///https://codeforces.com/problemset/problem/489/B
  2. #include<iostream>
  3. #include<vector>
  4. #include<algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int n;
  10.     cin >> n;
  11.     vector<int> a(n);
  12.     for (auto& e : a) cin >> e;
  13.     sort(a.begin(), a.end());
  14.     int m;
  15.     cin >> m;
  16.     vector<int> b(m);
  17.     for (auto& e : b) cin >> e;
  18.     sort(b.begin(), b.end());
  19.     vector<bool> is_taken(m, false);
  20.     int answ = 0;
  21.     for (int i = 0; i < n; i++) {
  22.         for (int j = 0; j < m; j++) {
  23.             if (!is_taken[j] && (abs(a[i] - b[j]) <= 1)) {
  24.                 answ++;
  25.                 is_taken[j] = true;
  26.                 break;
  27.             }
  28.         }
  29.     }
  30.     cout << answ;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement