➤ Problem Link : 550B. Preparing Olympiad
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n,l,r,x; cin>>n>>l>>r>>x; ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i]; ll cnt=0; ll sum=0; ll mn,mx; for(ll i=1;i<pow(2,n);i++) { mx=LONG_MIN,mn=LONG_MAX; sum=0; for(int j=0;j<n;j++) { if(i & 1<<j) { sum+=arr[j]; if(arr[j]>mx) mx=arr[j]; if(arr[j]<mn) mn=arr[j]; } } if(mx==mn || sum<l || sum>r || mx-mn<x) continue; cnt++; } cout<<cnt; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!