Iamtui1010

walkingstreet.cpp

Mar 13th, 2022
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<vector>
  4. #include<algorithm>
  5.  
  6. #define long long long
  7. #define nln '\n'
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     // Input
  14.     cin.tie(0)->sync_with_stdio(0);
  15.     cout.tie(0)->sync_with_stdio(0);
  16.     //freopen("walkingstreet.inp", "r", stdin);
  17.     long n, d;
  18.     cin >> n >> d;
  19.     vector<long> a(n);
  20.     for (auto &i : a)
  21.         cin >> i;
  22.     // Process
  23.     long ans = 0;
  24.     for (const auto i : a){
  25.         long pos = upper_bound(a.begin(), a.end(), i+d) - a.begin();
  26.         if (pos == n)
  27.             continue;
  28.         ans += n-pos;
  29.     }
  30.     // Output
  31.     cout << ans << nln;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment