Advertisement
Josif_tepe

Untitled

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