Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int N, K;
- cin >> N >> K;
- long long a[N];
- for(int i = 0; i < N;i++)
- cin >> a[i];
- sort(a, a + N);
- long long ans = 0;
- long long t;
- int j;
- for(int i = 0; i < N - 1; i++)
- {
- t = K + a[i] - 1;
- j = upper_bound(a + i, a + N, t) - a;
- if((a[j] - a[i]) >= K & j <= N - 1)
- ans += N - j;
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement