Advertisement
LEGEND2004

Number of Pairs

Jul 13th, 2023
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. signed main()
  8. {
  9.     int t , n , l , r;
  10.     cin >> t;
  11.     while(t--){
  12.         cin >> n >> l >> r;
  13.         vector<int> a(n);
  14.         for(int i = 0; i < n; i++){
  15.             cin >> a[i];
  16.         }
  17.         sort(a.begin() , a.end());
  18.         int ans = 0;
  19.         for(int i = 0; i < (n - 1); i++){
  20.             int g = l - a[i];
  21.             int x = lower_bound(a.begin() , a.end() , g) - a.begin();
  22.             g = r - a[i];
  23.             int y = upper_bound(a.begin() , a.end() , g) - a.begin() - 1;
  24.             x = max(x , i + 1);
  25.             if(y >= x)
  26.                 ans += (y - x + 1);
  27.         }
  28.         cout << ans << endl;
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement