fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7.  
  8. int arr[n+1];
  9.  
  10. for(int i=0; i<n; i++) {
  11. cin >> arr[i];
  12. }
  13.  
  14. int k;
  15. cin >> k;
  16.  
  17. int count = 0;
  18.  
  19. int i=0;
  20. int j = n-1;
  21.  
  22. while(i < j) {
  23. if(arr[i] + arr[j] > k) {
  24. count += (j-i);
  25. j--;
  26. } else {
  27. i++;
  28. }
  29. }
  30. cout << " Count of Quadruplets: " << count;
  31. return 0;
  32. }
Success #stdin #stdout 0s 5324KB
stdin
5
1
2
3
4
5
5
stdout
 Count of Quadruplets: 6