Advertisement
Josif_tepe

Untitled

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