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;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
long long n; long long x; cin >> n >> x;
long long a1[n/2], a2[(n+1)/2];
for (auto& y : a1) cin >> y;
for (auto& y : a2) cin >> y;
vector<long long> half;
for (long long mask = 0; mask < 1 << (n/2); mask++) {
long long sum = 0;
for (long long i = 0; i < n/2; i++) {
if (mask & (1 << i)) {
sum += a1[i];
}
}
if (sum <= x) half.push_back(sum);
}
sort(half.begin(), half.end());
long long cnt = 0;
for (long long mask = 0; mask < (1 << ((n+1)/2)); mask++) {
long long sum = 0;
for (long long i = 0; i < (n+1)/2; i++) {
if (mask & (1 << i)) {
sum += a2[i];
}
}
if (sum <= x) cnt += upper_bound(half.begin(), half.end(), x - sum) - half.begin();
}
cout << cnt;
}
# | 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... |