Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<vector>
- #include<algorithm>
- #define long long long
- #define nln '\n'
- using namespace std;
- int main()
- {
- // Input
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("walkingstreet.inp", "r", stdin);
- long n, d;
- cin >> n >> d;
- vector<long> a(n);
- for (auto &i : a)
- cin >> i;
- // Process
- long ans = 0;
- for (const auto i : a){
- long pos = upper_bound(a.begin(), a.end(), i+d) - a.begin();
- if (pos == n)
- continue;
- ans += n-pos;
- }
- // Output
- cout << ans << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment