This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 45
using namespace std;
long long arr[N];
vector<long long> v;
void solve(){
long long n,m;
cin >> n >> m;
for(int i=0;i<n;i++)cin >> arr[i];
long long ans = 0;
for(int i=0;i<(1<<(n/2));i++){
long long sum = 0;
for(int j=0;j<(n/2);j++){
if(i & ( 1<<j)){
sum += arr[j];
}
}
v.push_back(sum);
}
sort(v.begin(),v.end());
int c = n/2;
n -= n/2;
for(int i=0;i<(1<<n);i++){
long long sum = 0;
for(int j=0;j<n;j++){
if(i & ( 1<<j)){
sum += arr[c+j];
}
}
if(sum <=m){
ans += upper_bound(v.begin(),v.end(),m-sum) -v.begin();
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |