fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n,k; cin >> n >> k;
  6. vector<int> arr(n);
  7. for(int i = 0; i < n; i++)
  8. cin >> arr[i];
  9.  
  10. unordered_map<int,int> mp;
  11. int cnt = 0;
  12. for(int i = 0; i < n; i++){
  13. mp[arr[i]]++;
  14. }
  15. for(auto it : mp){
  16. int val = it.first;
  17. int req = val - k;
  18. if(mp.find(req) != mp.end())
  19. cnt++;
  20. }
  21. cout << cnt;
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5320KB
stdin
5 0
1 2 2 2 3
stdout
3