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>
using namespace std;
typedef long long ll;
const ll N = 42;
ll n, m, a[N];
int main(){
cin >> n >> m;
for (ll i=0; i<n; i++)
cin >> a[i];
ll x = n / 2;
vector<ll> left, right;
for (ll mask = 0; mask < (1<<x); mask ++){
ll sm = 0;
for (ll i = 0; i < x; i++){
if ((1 << i) & mask){
sm += a[i];
}
}
left.push_back(sm);
}
x += n%2;
for (ll mask = 0; mask < (1<<x); mask ++){
ll sm = 0;
for (ll i = 0; i < x; i++){
if ((1 << i) & mask){
sm += a[i + n / 2];
}
}
right.push_back(sm);
}
sort(left.begin(), left.end());
sort(right.begin(), right.end());
ll ans = 0;
for (ll x : left){
ll rem = m - x;
if (rem < 0)
break;
ll ub = upper_bound(right.begin(), right.end(), rem) - right.begin();
ans += ub;
}
cout << ans << 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... |