Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- long long n, k;
- cin >> n >> k;
- // cout<<n;
- multiset <int> ms;
- long long reshenie = 0;
- for(int i=0; i<n; i++){
- int a;
- cin>>a;
- ms.insert(a);
- if(k == 0){
- reshenie += ms.count(a) - 1;
- }
- else{
- reshenie += ms.count(a + k);
- reshenie += ms.count(a - k);
- }
- }
- cout << reshenie << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement