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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int ans=0;
int fn=(n/2);
vector<int> fh,sh;
for(int mask=0;mask<(1ll<<fn);mask++)
{
int sum=0;
for(int j=0;j<fn;j++)
if(mask&(1ll<<j))
sum+=a[j];
if(sum<=m)
fh.push_back(sum);
}
sort(begin(fh),end(fh));
int sn=n-fn;
for(int mask=0;mask<(1ll<<sn);mask++)
{
int sum=0;
for(int j=0;j<sn;j++)
if(mask&(1ll<<j))
sum+=a[j+fn];
if(sum<=m)
sh.push_back(sum);
}
for(auto i:sh)
ans+=upper_bound(begin(fh),end(fh),(m-i))-begin(fh);
cout<<ans<<endl;
return 0;
}
# | 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... |