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;
int N, M;
vector<int> nums;
vector<long long> half;
int main() {
ios_base::sync_with_stdio(false);
// freopen("1.in", "r", stdin);
cin >> N >> M;
nums.assign(N, 0);
for (int i = 0; i < N; i++)
cin >> nums[i];
for (int i = 0; i < (1 << (N / 2)); i++) {
long long sum = 0;
for (int j = 0; j < N / 2; j++)
if (i & (1 << j))
sum += nums[j];
half.push_back(sum);
}
sort(half.begin(), half.end());
long long res = 0;
for (int i = 0; i < (1 << (N - N / 2)); i++) {
long long sum = 0;
for (int j = N / 2; j < N; j++)
if (i & (1 << (j - N / 2)))
sum += nums[j];
int lo = 0, hi = half.size() - 1, ans = -1;
while (lo <= hi) {
int m = (lo + hi) / 2;
if (half[m] > M - sum)
hi = m - 1;
else
lo = m + 1, ans = m;
}
res += ans + 1;
}
cout << res << "\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... |