This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: zhougz
* created: 08/12/2021 14:48:56
**/
#include <bits/stdc++.h>
using namespace std;
// Man-in-the-middle attack again?
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
long long m;
cin >> n >> m;
vector<long long> arr;
arr.reserve(n);
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
if (x <= m) {
arr.push_back(x);
}
}
n = arr.size();
vector<long long> v;
const int c1 = (n + 1) / 2, c2 = n / 2;
assert(c1 + c2 == n);
v.reserve(1 << c1);
for (int i = 0; i < (1 << c1); i++) {
long long cur = 0;
for (int j = 0; j < c1; j++) {
if ((i >> j) & 1) {
cur += arr[j];
if (cur > m) {
goto end;
}
}
}
v.push_back(cur);
end:;
}
sort(v.begin(), v.end());
long long res = 0;
for (int i = 0; i < (1 << c2); i++) {
long long cur = 0;
for (int j = 0; j < c2; j++) {
if ((i >> j) & 1) {
cur += arr[c1 + j];
if (cur > m) {
goto end2;
}
}
}
res += upper_bound(v.begin(), v.end(), m - cur) - v.begin();
end2:;
}
cout << res;
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... |