fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int count = 0;
  6. int n,x;
  7. cin >> n >> x;
  8. int A[n];
  9. for (int i = 0; i < n; i++){
  10. cin >> A[i];
  11. }
  12. sort(A, A + n);
  13. int f = 0;
  14. int e = n -1;
  15. while (e >= f){
  16. if (A[f] + A[e] == x){
  17. count++;
  18. f++;
  19. }
  20. else if (A[f] + A[e] > x){
  21. e--;
  22. }
  23. else{
  24. f++;
  25. }
  26. }
  27. cout << count;
  28. }
Success #stdin #stdout 0s 5320KB
stdin
7 6
1 2 4 3 4 5 3 
stdout
4