Advertisement
Josif_tepe

Untitled

Oct 23rd, 2022
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int k, n;
  8.     cin >> k >> n;
  9.     vector<int> a(n), b(n);
  10.      
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> a[i];
  13.     }
  14.     for(int i = 0; i < n; i++) {
  15.         cin >> b[i];
  16.     }
  17.     sort(a.begin(), a.end());
  18.     sort(b.begin(), b.end());
  19.     long long result = 0;
  20.     for(int i = 0; i < n; i++) {
  21.         int x = k - a[i];
  22.         int idx = lower_bound(b.begin(), b.end(), x) - b.begin();
  23.         if(idx >= 0 and idx < n) {
  24.             result += n - idx;
  25.         }
  26.     }
  27.     cout << result << endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement