fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;cin>>n;
  6. int k;cin>>k;
  7. vector<int> arr(n);
  8. unordered_map<int,int> mp;
  9. int count=0;
  10. for(int j=0;j<n;j++)
  11. {
  12. cin>>arr[j];
  13. int x=k+arr[j];
  14. int y=arr[j]-k;
  15. if(k==0)
  16. {
  17. count+=mp[x];
  18. }
  19. else
  20. {count+=mp[x];
  21. count+=mp[y];
  22. }
  23. mp[arr[j]]++;
  24. }
  25. cout<<count;
  26.  
  27.  
  28.  
  29.  
  30. }
  31.  
  32.  
  33.  
  34.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
-1652140543