fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n ;
  6. cin>>n;
  7. int target;
  8. cin>>target;
  9. int arr[n];
  10. for(int i = 0; i< n ; i++){
  11. cin>>arr[i];
  12. }
  13. int count = 0;
  14. unordered_map<int,int> mpp;
  15. for(int j = 0; j< n ; j++){
  16. int r = target - arr[j];
  17. if(mpp.count(r)){
  18. count += mpp[r];
  19. }
  20. mpp[arr[j]] = mpp[arr[j]] + 1;
  21. }
  22. cout << count;
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5308KB
stdin
5
8
2 5 3 6 1
stdout
2