fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,l,r,x; cin>>n>>l>>r>>x;
  6. int ara[n+9], ans=0;
  7. for(int i=1; i<=n; i++) cin>>ara[i];
  8.  
  9. for(int i=1; i<(1<<n); i++){
  10. int mx=0, sum=0, mn=1e9+9;
  11. for(int j=1; j<=n; j++){
  12. if(i&(1<<(j-1))) {
  13. sum+=ara[j];
  14. mx=max(mx, ara[j]);
  15. mn=min(mn, ara[j]);
  16. }
  17. }
  18. if(mx-mn>=x and sum>=l and sum<=r) ans++;
  19. }
  20. cout<<ans<<endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 4396KB
stdin
4 40 50 10
10 20 30 25
stdout
2