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>
using namespace std;
long long n,n1,n2,m,a[21],b[21];
vector<long long>v1,v2;
int main(){
cin>>n>>m;
n1=n/2;
n2=n-n/2;
for(int i=1;i<=n1;i++){
cin>>a[i];
}
for(int i=1;i<=n2;i++){
cin>>b[i];
}
for(int i=0;i<(1ll<<n1);i++){
long long sum=0;
for(int j=0;j<n1;j++){
if(i&(1ll<<j)){
sum+=a[j+1];
}
}
v1.push_back(sum);
}
for(int i=0;i<(1ll<<n2);i++){
long long sum=0;
for(int j=0;j<n2;j++){
if(i&(1ll<<j)){
sum+=b[j+1];
}
}
v2.push_back(sum);
}
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
long long ans=0;
for(long long i:v1){
ans+=upper_bound(v2.begin(),v2.end(),m-i)-v2.begin();
}
cout<<ans<<endl;
}
# | 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... |