Skip to content

Instantly share code, notes, and snippets.

@balamark
Created June 6, 2015 01:28
Show Gist options
  • Select an option

  • Save balamark/81fc888175637660bd9f to your computer and use it in GitHub Desktop.

Select an option

Save balamark/81fc888175637660bd9f to your computer and use it in GitHub Desktop.
CF306 b
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <unordered_map>
#include <bitset>
using namespace std;
typedef vector<int> vi;
int main(){
int n,l,r,x;
cin>>n>>l>>r>>x;
vi v(n, 0);
for(int i=0;i<n;++i) cin>>v[i];
int cnt=0;
//search all 2^n
for(int i=0;i<(1<<n);++i){
int total=0;
int sm = 1000000, lg = 0;
for(int p=0;p<n;++p) if((1<<p)&i){
total += v[p];
sm = min(sm, v[p]);
lg = max(lg, v[p]);
}
//check constraints
if(lg-sm>=x && total<=r && total>=l) cnt++;
}
cout<<cnt<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment