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 41
using namespace std;
typedef long long ll;
ll n, v[N], ans, k;
vector<ll> val;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>k;
for(int i = 0; i < n; i++) cin>>v[i];
int m = n/2;
for(int mask = 1; mask <= ( (1<<(m + 1)) - 1) ; mask ++)
{
ll sum = 0;
for(int i = 0; i <= m; i++)
{
if( (mask & (1<<i)) )
{
sum += v[i];
}
}
if(sum <= k) ans ++;
val.push_back(sum);
}
sort(val.begin(), val.end());
for(int mask = 1; mask <= ( (1<<(n - m - 1)) - 1) ; mask ++)
{
ll sum = 0;
for(int i = m + 1; i < n; i++)
{
int j = i - m - 1;
if( (mask & (1<<j)) )
{
sum += v[i];
}
}
if(sum <= k)
{
//cout<<sum<<" "<< (upper_bound(val.begin(), val.end(), k - sum) - val.begin())<<"\n";
ans += upper_bound(val.begin(), val.end(), k - sum) - val.begin() + 1;
}
}
cout<<ans + 1<<"\n";
}
# | 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... |