fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. main(){
  5. int n,k1,k2;
  6. long long ans=0;
  7. cin>>n>>k1>>k2;
  8. vector<int>v(n);
  9. for(auto &it:v)cin>>it;
  10.  
  11. for(int i=0,j=1;j<n-2;j++){
  12. int c1=0,c2=0;
  13.  
  14. while(v[i]+v[j]<=k1)i++;
  15.  
  16. c1=j-i;
  17.  
  18. int k=j+1,l=n-1;
  19.  
  20. while(k<l){
  21. if(v[k]+v[l]>k2){
  22. c2+=l-k;
  23. l--;
  24. }
  25. else k++;
  26. }
  27.  
  28. ans+=c1*c2;
  29. }
  30. cout<<ans<<"\n";
  31. }
Success #stdin #stdout 0.01s 5324KB
stdin
6 1 3
1 1 1 1 2 2
stdout
6