fork download
  1. #include <iostream>
  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. for(int i = 0; i< n ; i++){
  15. for(int j = i+1;j< n ; j++){
  16. if(arr[i]+arr[j] == target){
  17. count +=1;
  18. }
  19. }
  20. }
  21. cout << count;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 5308KB
stdin
5
8
2 5 3 6 1
stdout
2