Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define int long long
- #define ld long double
- const int inf = 1e9;
- ll M2 = 1e9 + 9, M1 = 1e9 + 7;
- //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
- void solve() {
- int n, r;
- cin >> n >> r;
- vector<int> a(n);
- for (auto &x : a) {
- cin >> x;
- }
- int ans = 0;
- int j = -1;
- for (int i = 0; i < n; ++i) {
- while (j == -1 || a[i] - a[j] > r) {
- ++j;
- }
- ans += j;
- }
- cout << ans << '\n';
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- ll thrush = 1;
- //cin >> thrush;
- while (thrush--) { solve();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement