fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n;int target;
  7. cin>>n;cin>>target;
  8. vector <int> ar;
  9. for(int i=0;i<=n-1;i++){
  10. int y;cin>>y;
  11. ar.push_back(y);
  12. }
  13.  
  14. int count =0;
  15. unordered_map<int,int>mpp;
  16.  
  17. for(int j=0;j<n;j++){
  18. int rem = target-ar[j];
  19.  
  20. if(mpp.find(rem)!=mpp.end())
  21. count+=mpp[rem];
  22.  
  23. mpp[ar[j]]++;
  24. }
  25. cout<<count;
  26.  
  27. // your code goes here
  28. return 0;
  29. }
Success #stdin #stdout 0s 5320KB
stdin
6 5 
2 2 3 3 5 5
stdout
4