fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. vector<int> arr={1,3,4,5,8};
  6. int n=arr.size();
  7. int i=0, j=n-1 , count=0 ,k=5;
  8. while(i<j){
  9. if(arr[i]+arr[j]<=k){
  10. i++;
  11. }else{
  12. count=count+j-i;
  13. j--;
  14. }
  15.  
  16. }
  17. cout<<count<<endl;
  18. return 0;
  19. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
8