fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,x ; cin>>n>>x;
  7. vector<int>arr(n);
  8. for(int i = 0 ; i<n;i++){
  9. cin>>arr[i];
  10. }
  11. int count = 0 ;
  12. unordered_map<int,int>hash;
  13. for(int i =0;i<n;i++){
  14. if(hash.find(x-arr[i])!=hash.end()){
  15. count+=hash[x-arr[i]];
  16. }
  17. hash[arr[i]]++;
  18. }
  19. cout<<count;
  20. // your code goes here
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5316KB
stdin
6 10
3 5 2 8 7 1
stdout
2