Advertisement
Josif_tepe

Untitled

Apr 6th, 2024
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     int k, n;
  10.     cin >> k >> n;
  11.    
  12.     int a[n], b[n];
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> a[i];
  15.     }
  16.     for(int i = 0; i < n; i++) {
  17.         cin >> b[i];
  18.     }
  19.    
  20.     sort(a, a + n);
  21.     sort(b, b + n);
  22.    
  23.     long long res = 0;
  24.     for(int i = 0; i < n; i++) {
  25.         if(a[i] >= k) {
  26.             res += n;
  27.         }
  28.         else {
  29.             int x = k - a[i];
  30.             int idx = lower_bound(b, b + n, x) - b;
  31.             if(idx >= 0 and idx < n) {
  32.                 res += n - idx;
  33.             }
  34.            
  35.         }
  36.     }
  37.     cout << res << endl;
  38.     return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement