Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<algorithm>
- #include <fstream>
- #include <map>
- using namespace std;
- int main()
- {
- // ifstream cin("out.txt");
- long long n,k;
- cin>>n>>k;
- long long a[n];
- map<long long, long long> m;
- for(int i=0;i<n;i++)
- {
- cin>>a[i];
- m[a[i]]++;
- }
- sort(a,a+n);
- long long s=0;
- // for(int i =0; i < n; i++) {
- // cout << a[i] << " " ;
- // }
- // cout << endl;
- for(int i=0;i<n;i++)
- {
- s += m[a[i] - k];
- }
- if(k == 0) {
- s -= n;
- s /= 2;
- }
- cout<<s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement