Salvens

C

Aug 7th, 2023
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. #define int long long
  7.  
  8. const long long INF = 1e9 + 7;
  9. const int MAXN = 200 + 10;
  10. const int N = 1e5 + 10;
  11.  
  12. signed main() {
  13.     ios_base::sync_with_stdio(false);
  14.     cin.tie(nullptr);
  15.     cout.tie(nullptr);
  16.  
  17.     int n, s;
  18.     cin >> n >> s;
  19.     vector<int> a(n);
  20.     for (int i = 0; i < n; ++i) {
  21.         cin >> a[i];
  22.     }
  23.  
  24.     int ans = 0, l = 0;
  25.     for (int r = 0; r < n; ++r) {
  26.         while (a[r] - a[l] > s && l <= r) {
  27.             ++l;
  28.         }
  29.         ans += l;
  30.     }
  31.     cout << ans << '\n';
  32. }
Advertisement
Add Comment
Please, Sign In to add comment