Advertisement
messh

Untitled

Jul 9th, 2025
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define int long long
  5. #define ld long double
  6. const int inf = 1e9;
  7.  
  8. ll M2 = 1e9 + 9, M1 = 1e9 + 7;
  9. //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  10.  
  11.  
  12.  
  13. void solve() {
  14.     int n, r;
  15.     cin >> n >> r;
  16.     vector<int> a(n);
  17.     for (auto &x : a) {
  18.         cin >> x;
  19.     }
  20.     int ans = 0;
  21.     int j = -1;
  22.     for (int i = 0; i < n; ++i) {
  23.         while (j == -1 || a[i] - a[j] > r) {
  24.             ++j;
  25.         }
  26.         ans += j;
  27.     }
  28.     cout << ans << '\n';
  29.  
  30.  
  31. }
  32.  
  33. signed main() {
  34.  
  35.  
  36.     ios_base::sync_with_stdio(false);
  37.     cin.tie(nullptr);
  38.     ll thrush = 1;
  39.     //cin >> thrush;
  40.     while (thrush--) { solve();}
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement