#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int int_fast64_t
#define ul uint_fast32_t
#define ll int_fast64_t
#define dll long double
#define ull uint_fast64_t
#define spektar this_thread::sleep_for(chrono::milliseconds(1000))
void solve(){
ll n,m;
cin >> n >> m;
vector<ll> k(n);
for(int i=0; i<n; i++) cin >> k[i];
vector<ll> kk;
ll ss=0;
kk.push_back(0);
for(ll i=0; i<(1<<(n/2)); i++){
ll s=0;
for(int j=0; j<n/2; j++){
if((1<<j)&i){
s+=k[j];
}
}
if(s<=m){
kk.push_back(s);
}
}
sort(kk.begin(),kk.end());
for(ll i=0; i<(1<<(n-n/2)); i++){
ll s=0;
for(int j=n/2; j<n; j++){
if((1<<(j-n/2))&i){
s+=k[j];
}
}
ll a;
if(lower_bound(kk.begin(),kk.end(),m-s)==kk.end()) a=kk.size();
else if(lower_bound(kk.begin(),kk.end(),m-s)==kk.begin()) a=0;
else a=lower_bound(kk.begin(),kk.end(),m-s)-kk.begin();
ss+=a;
}
cout << ss-1 << endl;
}
signed main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
| # | 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... |