Advertisement
josiftepe

Untitled

Mar 6th, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     int k, n;
  10.     cin >> k >> n;
  11.     vector<int> a(n), b(n);
  12.     for(int &x : a) {
  13.         cin >> x;
  14.     }
  15.     for(int &x : b) {
  16.         cin >> x;
  17.     }
  18.     sort(a.begin(), a.end());
  19.     sort(b.begin(), b.end());
  20.     long long ret = 0;
  21.     for(int i = 0; i < n; i++) {
  22.         int left = k - a[i];
  23.         if(left < 0) continue;
  24.        int cnt =  (int)(upper_bound(b.begin(), b.end(), left - 1) - b.begin());
  25.         if(cnt >= 0 and cnt <= n) {
  26.             ret += cnt;
  27.         }
  28.     }
  29.    
  30.     long long all = (long long)(n) * (long long)(n);
  31.     cout << all - ret << endl;
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement