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 F first
#define S second
#define ll long long
#define pii pair<ll,ll>
const ll mxN = 2e5 + 5;
const ll mod = 1e9 + 7;
using namespace std;
vector<ll>v;
ll a[50];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n,m;
ll ans = 0;
cin >>n>>m;
for(ll i = 0;i < n;i++) cin >>a[i];
ll hf = n / 2,sf = (n + 1) / 2;
for(ll mask = 0;mask < (1 << hf);mask++){
ll sum = 0;
for(ll i = 0;i < hf;i++){
if((mask >> i) % 2){
sum += a[i];
if(sum > m) break;
}
}
if(sum > m) continue;
v.push_back(sum);
}
// cout<<'\n';
sort(v.begin(),v.end());
// for(auto x : v) cout<<x<<' ';
// cout<<'\n';
for(ll mask = 0;mask < (1 << sf);mask++){
ll sum = 0;
for(ll i = 0;i < sf;i++){
if((mask >> i) % 2){
sum += a[i + hf];
if(sum > m) break;
}
}
if(sum > m) continue;
ans += upper_bound(v.begin(),v.end(),m - sum) - v.begin();
// cout<<sum<<' '<<upper_bound(v.begin(),v.end(),m - sum) - v.begin()<<'\n';
}
cout<<ans;
}
# | 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... |