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 all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
int32_t main() {
int n;
ll m, ans = 1;
cin >> n >> m;
vector<ll> v(n);
for(ll &x : v) cin >> x;
auto meet = [&](int l, int r) {
vector<ll> total;
int len = r - l + 1;
for(int s=1; s<(1<<len); s++) {
ll sum = 0;
for(int i=0; i<len; i++)
if(s & (1 << i)) sum += v[l+i];
total.push_back(sum);
if(sum <= m) ans++;
}
sort(all(total));
return total;
};
vector<ll> L = meet(0, n/2-1);
vector<ll> R = meet(n/2, n-1);
for(ll &x : L) {
int l=0, r=R.size()-1, p=-1;
while(l <= r) {
int mid = (l + r) / 2;
if(x + R[mid] <= m) p = mid, l = mid + 1;
else r = mid - 1;
}
ans += p + 1;
}
cout << ans << '\n';
return 0;
}
# | 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... |