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;
typedef long long ll;
int main()
{
int n;
cin>>n;
ll k;
cin>>k;
vector<ll>v;
int p=n/2;
int p1=n-p;
vector<ll>vc;
for(int i=0;i<n;i++)
{
ll a;
cin>>a;
v.push_back(a);
}
ll res=0;
for(int i=1;i<(1<<p);i++)
{
ll s=0;
for(int j=0;j<p;j++)
{
if(i&(1<<j))
{
s+=v[j];
}
}
if(s<=k)
{
vc.push_back(s);
res++;
}
}
sort(vc.begin(),vc.end());
for(int i=1;i<(1<<p1);i++)
{
ll s=0;
for(int j=0;j<p1;j++)
{
if(i&(1<<j))
{
s+=v[j+p];
}
}
if(s<=k)
{
res++;
res+=(upper_bound(vc.begin(),vc.end(),k-s)-vc.begin());
}
}
res++;
cout<<res<<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... |