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