Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <cstdio>
- #include <cstdlib>
- #include <cctype>
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <cstdio>
- #include <cstdlib>
- #include <cctype>
- #include <cmath>
- #include <ctime>
- using namespace std;
- typedef long long LL;
- #define FOR(k,a,b) for(int k(a); k < (b); ++k)
- #define REP(k,a) for(int k=0; k < (a); ++k)
- int main()
- {
- int N,A,B;
- cin >> N >> A >> B;
- vector<LL> S(N);
- LL res=0;
- REP(i,N)
- {
- cin >> S[i] ;
- }
- vector<LL> v;
- int vi=N/2,wi=N-vi;
- REP(i,1<<vi)
- {
- v.push_back(0);
- REP(j,vi)
- {
- if((1<<j) &i )
- v.back()+=S[j];
- }
- if(v.back()>=A && v.back()<=B)
- ++res;
- }
- sort(v.begin(),v.end());
- FOR(i,1,1<<wi)
- {
- LL w=0;
- REP(j,wi)
- {
- if((1<<j) &i )
- w+=S[j+vi];
- }
- //binary search
- //w+v_i>=A => min i: v_i>=A-w
- //w+v_i<=B => max i: v_i<=B-w
- w=A-w;
- vector<LL>::iterator low=lower_bound(v.begin(),v.end(),w);
- w=B-A+w;
- LL dist=0;
- vector<LL>::iterator up=upper_bound(v.begin(),v.end(),w);
- dist=distance(low,up);
- res+=dist;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment