fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void Halmantechy()
  4. {
  5. cin.tie(0);
  6. cin.sync_with_stdio(0);
  7. cout.tie(0);
  8. cout.sync_with_stdio(0);
  9. }
  10. int main()
  11. {
  12. Halmantechy();
  13. int n,target; cin >> n;
  14. int arr[n];
  15. int counter = 0;
  16. for (int i=0; i<n;i++)
  17. {
  18. cin >> arr[i];
  19. }
  20. sort(arr,arr+n);
  21. target = arr[0] + arr[n-1];
  22. for (int i =0;i < n-1;i++)
  23. {
  24. for(int j=i+1;j<n;j++)
  25. {
  26. if (arr[i]+arr[j] == target && i < j)
  27. {
  28. counter++;
  29. }
  30. }
  31. }
  32. cout << counter;
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.53s 5292KB
stdin
Standard input is empty
stdout
2