fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n;int tg;
  7. cin>>n;cin>>tg;
  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.  
  15. int ct = 0;
  16. unordered_map<int, int> mp;
  17.  
  18. for (int j = 0; j < n; j++) {
  19. int df = tg - ar[j];
  20.  
  21. if (mp.count(df)) {
  22. ct += mp[df];
  23. }
  24.  
  25. mp[ar[j]]++;
  26. }
  27.  
  28. cout << ct << endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
0