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;
#define ll long long
int n;
ll m;
vector<ll> lsums, rsums;
ll ans = 0LL;
ll nums[50];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> nums[i];
}
int mid = n/2;
for (int mask = 0; mask < (1 << mid); mask++) {
ll sum = 0LL;
for (int i = 1; i <= mid; i++) {
if (mask & (1 << (i-1))) {
sum += nums[i];
}
}
lsums.push_back(sum);
}
int onum = n-mid;
for (int mask = 0; mask < (1 << onum); mask++) {
ll sum = 0LL;
for (int i = mid+1; i <= n; i++) {
if (mask & (1 << (i - mid-1))) {
sum += nums[i];
}
}
rsums.push_back(sum);
}
sort(lsums.begin(), lsums.end());
sort(rsums.begin(), rsums.end());
for (ll val : lsums) {
ans += upper_bound(rsums.begin(), rsums.end(),
m-val) - rsums.begin() + 0LL;
}
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... |