Advertisement
Josif_tepe

Untitled

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