fork download
  1. #include<iostream>
  2. #include<unordered_set>
  3. using namespace std;
  4. unordered_set<int> s;
  5. int main()
  6. {
  7. int n, k, val;
  8. cin >> n >> k;
  9. for (int i = 0; i < n; i++)
  10. {
  11. cin >> val;
  12. s.insert(val);
  13. }
  14. int ans = 0;
  15. for (unordered_set<int>::iterator it = s.begin(); it != s.end(); ++it)
  16. if (s.find(*it + k) != s.end()) ans++;
  17. cout << ans << endl;
  18. return 0;}
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1